-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquake_monitor.py
executable file
·42 lines (36 loc) · 1.42 KB
/
quake_monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/home/remote_damien/miniconda/bin/python
import usgs
import time
import tweepy
import traceback
import pandas as pd
from mapping import *
class Quake_bot:
def __init__(self, config_file):
df = pd.read_csv(config_file, header=None, index_col=[0]).transpose()
consumer_key = df.consumer_key.iloc[0]
consumer_secret = df.consumer_secret.iloc[0]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
access_token = df.access_token.iloc[0]
access_token_secret = df.access_token_secret.iloc[0]
auth.set_access_token(access_token, access_token_secret)
self.google_api = df.google_api.iloc[0]
self.api = tweepy.API(auth)
def tweet(self, message, latitude, longitude):
try:
get_map(latitude, longitude, api=self.google_api)
self.api.update_with_media("map.png", status=message)
except tweepy.TweepError as e:
print(e.message[0]["message"])
bots = {}
bots["Washington"] = Quake_bot("/app/data/botWA.config")
bots["California"] = Quake_bot("/app/data/botSoCal.config")
# bots['California'] =Quake_bot('botWA.config')
while True:
try:
usgs.readfeed(bots)
except Exception as e:
print(traceback.format_exc())
# Twitter bot code checks for new quakes, tweets
time.sleep(60 * 10)
# usgs.readfeed(bots, feed_url='http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson')