Example #1
0
def send_alert(body):
    client = Client(API().account_sid, API().auth_token)
    try:
        message = client.messages.create(from_=API().from_,
                                         body=body,
                                         to=API().to)

        return message.sid
    except:
        return False
Example #2
0
 def request_tweet(self, file):
     tweets = API.tweet_api(self.topic)
     tweet_list = []
     for tweet in tweets:
         tweetTime = tweet[0].created_at
         tweetText = API.clean_tweet(tweet[0].text)
         tweetTS = time.mktime(tweetTime.timetuple())
         if not tweet[0].retweeted:
             tweet_content = {int(tweetTS): tweetText}
             tweet_list.append(tweet_content)
             json.dump(tweet_content, file)
             file.write("\n")
     return tweet_list
Example #3
0
def cfg():
    # convert API config to Ext.Direct spec
    actions = {}
    for aname, a in API.iteritems():
        methods = []
        for mname, m in a['methods'].iteritems():
            if m.has_key('len'):
                md = {
                    'name': mname,
                    'len': m['len']
                }
            else:
                md = {
                    'name': mname,
                    'params': m['params']
                }
            if m.has_key('formHandler') and m['formHandler']:
                md['formHandler'] = True
            methods.append(md)
        actions[aname] = methods
    
    return json.dumps({
        'url': request.url_root.rstrip('/') + url_for('direct.router'),
        'type': 'remoting',
        'actions': actions
    })
Example #4
0
 def request_news(self):
     response = urllib2.urlopen(API.news_api(self.symbol))
     html = response.read()
     content = demjson.decode(html)
     article_list = []
     news_json = content['clusters']
     for cluster in news_json:
         for article in cluster:
             if article == 'a':
                 article_list.extend(cluster[article])
     return article_list
Example #5
0
def get_location(latlng):
    geolocation_api = 'https://maps.googleapis.com/maps/api/geocode/json?latlng={}&key={}'.format(
        latlng,
        API().API_KEY)
    response = requests.get(geolocation_api)
    if response.json().get('results'):
        return {
            'Address':
            response.json().get('results')[0].get('formatted_address'),
            'Location':
            response.json().get('results')[0]['geometry']['location'],
            'Location_type':
            response.json().get('results')[0].get('location_type')
        }
    return {}
Example #6
0
 def check_open_id(self, open_id, merchant_id, username):
     if API.get('WEIXIN') is None:
         raise gen.Return(False)
     url = "{}/webchart/user/ebk/has_bind_wechat?merchantId={}&username={}&openId={}".format(
         API['WEIXIN'], merchant_id, username, open_id)
     resp = yield AsyncHTTPClient().fetch(url)
     Log.info(resp.body)
     if resp.code == 200:
         r = json.loads(resp.body)
         if r and r['errcode'] == 0:
             raise gen.Return(True)
         else:
             self.logout()
             raise gen.Return(False)
     else:
         raise JsonException(500, 'call weixin server error')
Example #7
0
 def find_trends(self):
     trends = []
     places = API.trends_closest(self.lat, self.longt)
     for place in places:
         trends.append(API.trends_place(place['woeid']))
     return trends
Example #8
0
# twilio for sending msg alert
from twilio.rest import Client
# ibm cloudant
from cloudant import Cloudant
from cloudant.adapters import Replay429Adapter

# algolia search api
from algoliasearch import algoliasearch

#Importing the flood risk data
sheetname = "NOAA"
noaa = pd.read_excel("./Datasets/DataVizFloodsFV3_22_2017.xlsx",
                     sheet_name=sheetname)

# algolia app connection
client = algoliasearch.Client(API().app_id, API().admin_api_key)
index = client.init_index('ema')

# Flask app connection
app = Flask(__name__)
app.secret_key = 'ResQU'
app.config['SESSION_TYPE'] = 'filesystem'

# cloudant Connection
client = None
db_name = 'resqu'
db = None

if 'VCAP_SERVICES' in os.environ:
    vcap = json.loads(os.getenv('VCAP_SERVICES'))
    if 'cloudantNoSQLDB' in vcap:
Example #9
0
 def request_sentiment(self):
     sentiment = API.sentiment_api(self.symbol)
     return sentiment