From 3f93e1002f7de0ef9ab7fb507e31442081419fcd Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 5 Jun 2020 14:00:07 -0700 Subject: Add quakes, human, and pick/drop --- drop | 2 ++ human | 3 +++ pick | 4 ++++ quakes | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100755 drop create mode 100755 human create mode 100755 pick create mode 100644 quakes diff --git a/drop b/drop new file mode 100755 index 0000000..6680676 --- /dev/null +++ b/drop @@ -0,0 +1,2 @@ +#!/bin/sh +xargs -0 -I'{}' cp '{}' . < ~/.pick && rm -f ~/.pick diff --git a/human b/human new file mode 100755 index 0000000..1ea1870 --- /dev/null +++ b/human @@ -0,0 +1,3 @@ +#!/usr/bin/env -S nim e + +echo "hello" diff --git a/pick b/pick new file mode 100755 index 0000000..dd0758b --- /dev/null +++ b/pick @@ -0,0 +1,4 @@ +#!/bin/sh +for i; do + printf '%s/%s\0' "$PWD" "$i" >> ~/.pick +done diff --git a/quakes b/quakes new file mode 100644 index 0000000..d1599c4 --- /dev/null +++ b/quakes @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 + +"""Print earthquakes near a given location. + +- i should be able to query for time since, like "show me earthquakes near me +for the last 2 months" + +this was all copied, i need to redo it: + +""" + +from bs4 import BeautifulSoup +import requests +from collections import OrderedDict + +""" +returns a list of list +at index =0, there is header +rest lists are real data +""" + + +def get_recent(url): + result = [] + response = requests.get(url) + if response.status_code != 200: + return [] + + extractor = BeautifulSoup(response.content, "html.parser") + # content = extractor.find_all("div", {'class': 'block2-content'})[0] + content = extractor.find_all("div", {"class": "data_table_wrapper"})[0] + table = content.find_all(["tr"]) + + # table header shit + table_header = table[0] + header_list = [data.get_text() for data in table_header("td")][:-1] + + result.append(header_list) + + """ + table = table[1::] + for row in table: + table_data = [ td.get_text() for td in row.find_all('td') if not td('form')] + data = OrderedDict() + for index, val in enumerate(table_data): + data[header_list[index]] = val + result.append(data) + """ + + table = table[1::] + for row in table: + table_data = [td.get_text() for td in row.find_all("td") if not td("form")] + result.append(table_data) + return result + + +def print_table(table): + table = table[1::] + for row in table: + for data in row: + print("{:15s}".format(data), end="") + print("\n") + + +def main(): + url = "http://www.seismonepal.gov.np/" + print("source: {}".format(url)) + print("-" * 100) + earthquake = get_recent(url) + print_table(earthquake) + + +if __name__ == "__main__": + main() -- cgit v1.2.3