diff options
author | Ben Sima <ben@bsima.me> | 2020-06-05 14:00:07 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-06-05 14:00:35 -0700 |
commit | 3f93e1002f7de0ef9ab7fb507e31442081419fcd (patch) | |
tree | 4e6a77771ae67a30cf3eaeb06b9a26b3f016cc52 | |
parent | 381b7d5d476b6c730fefbb26927251cb4a016ffa (diff) |
Add quakes, human, and pick/drop
-rwxr-xr-x | drop | 2 | ||||
-rwxr-xr-x | human | 3 | ||||
-rwxr-xr-x | pick | 4 | ||||
-rw-r--r-- | quakes | 74 |
4 files changed, 83 insertions, 0 deletions
@@ -0,0 +1,2 @@ +#!/bin/sh +xargs -0 -I'{}' cp '{}' . < ~/.pick && rm -f ~/.pick @@ -0,0 +1,3 @@ +#!/usr/bin/env -S nim e + +echo "hello" @@ -0,0 +1,4 @@ +#!/bin/sh +for i; do + printf '%s/%s\0' "$PWD" "$i" >> ~/.pick +done @@ -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() |