summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-06-05 14:00:07 -0700
committerBen Sima <ben@bsima.me>2020-06-05 14:00:35 -0700
commit3f93e1002f7de0ef9ab7fb507e31442081419fcd (patch)
tree4e6a77771ae67a30cf3eaeb06b9a26b3f016cc52
parent381b7d5d476b6c730fefbb26927251cb4a016ffa (diff)
Add quakes, human, and pick/drop
-rwxr-xr-xdrop2
-rwxr-xr-xhuman3
-rwxr-xr-xpick4
-rw-r--r--quakes74
4 files changed, 83 insertions, 0 deletions
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()