-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtrip.py
60 lines (49 loc) · 1.44 KB
/
trip.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import tweepy
from textblob import TextBlob
from calendar import month_name
import re
import json
import demjson
import requests
import pprint
import pandas as pd
import csv
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
types = ['discovering', 'eating', 'going_out', 'hiking', 'playing', 'relaxing', 'shopping', 'sightseeing', 'sleeping', 'doing_sports', 'traveling']
all_locations = pd.read_csv('api-cities.csv')
locations = all_locations['name']
from flask import request
from flask import Flask
app = Flask(__name__)
@app.route("/salil")
def main():
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
public_tweets = api.search('SmartTourister')
json_list = []
for tweet in public_tweets:
print(tweet.text)
for loc in locations:
loc = unicode(loc, 'utf-8')
if loc in tweet.text:
print('Source :: ',loc)
source = loc
for ty in types:
if ty in tweet.text.lower():
print('Type :: ',ty)
api_type = ty
mail = re.search(r'[\w\.-]+@[\w\.-]+', tweet.text.lower())
print('Email :: ',mail)
data = [ { 'Source' : source, 'Email' : mail,'Types' : api_type } ]
js = demjson.encode(data)
json_list.append(js)
json_string = json.dumps(json_list)
print json_string
print "*********"
return json_string
if __name__ == "__main__":
app.run(host='0.0.0.0',port=7890)