· 9 years ago · Jun 24, 2016, 08:06 PM
1import praw
2import json
3import requests
4import tweepy
5import time
6
7access_token = ['3319047260-hYs0OiGb1uvurlm0HUXIyTKKFjmJL7hIs1MfblX','3319731960-fL63tqQGoIfmMPzzSyELBMy89dcpp5IfVciiILj']
8access_token_secret = ['ehPksk8oAl7k0oMaJVm4ouzGrmSwpphb57O6cvBTjXCWr','HlCTmIMyNylBIMU3jPyvNbb0ryb3Du70WRTFbpBsgNSfG']
9consumer_key = ['rTkDstUS2cEVfo1WA9ih9uHJ5','w2NRYFX4grBVJYNULE0V0m3mL']
10consumer_secret = ['WpzXZq7s0q18rpypeWZTMfJG3zTINJkeNeGnEtLHoRL3n3Ek6L','WNWTCmUZ2AMNQp74Tbv1xsCgylPvG9v7jaVHx6XGCegv0Bj0tV']
11
12
13import MySQLdb,json,datetime
14import requests
15# configuration
16DATABASE = 'zipStreet'
17DB_SERVER = 'localhost'
18DEBUG = True
19SECRET_KEY = 'epicMedia123'
20USERNAME = 'root'
21PASSWORD = 'babamanohar'
22
23#Mysql Connection Declaration
24db = MySQLdb.connect(DB_SERVER,USERNAME,PASSWORD,DATABASE)
25db.autocommit(True)
26cursor = db.cursor()
27
28#Redis Declaration
29
30import redis
31
32redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
33
34def shorten(url):
35 headers = {'content-type': 'application/json'}
36 payload = {"longUrl": url}
37 url = "https://www.googleapis.com/urlshortener/v1/url"
38 r = requests.post(url, data=json.dumps(payload), headers=headers)
39 link = json.loads(r.text)
40 print link
41 return link
42
43
44def tweeter_cities():
45 auth = tweepy.OAuthHandler(consumer_key[0], consumer_secret[0])
46 auth.set_access_token(access_token[0], access_token_secret[0])
47 api = tweepy.API(auth)
48 cursor.execute('select distinct state from zipcodes')
49 states = [state[0] for state in cursor.fetchall()][1:]
50 urls = []
51 for state in states:
52 cursor.execute('select distinct city from zipcodes where state = "%s" '%state)
53 cities = [city[0] for city in cursor.fetchall()]
54
55 for city in cities:
56 urls.append(('http://zipcodestreet.net/'+state.replace(" ","-")+'/'+city.replace(" ","-"),city,state))
57
58 for url in urls[172:]:
59 api.update_status(status="Find Zipcodes Of City "+url[1]+", State "+url[2]+" : "+url[0])
60 print url[0]
61 time.sleep(30)
62
63def tweeter_zipcodes():
64 auth = tweepy.OAuthHandler(consumer_key[1], consumer_secret[1])
65 auth.set_access_token(access_token[1], access_token_secret[1])
66 api = tweepy.API(auth)
67 cursor.execute('select state,city,zipcode from zipcodes')
68
69 urls = []
70 for data in cursor.fetchall():
71 state = data[0]
72 city = data[1]
73 zipcode = data[2]
74 urls.append(('http://zipcodestreet.net/'+state.replace(" ","-")+'/'+city.replace(" ","-")+'/'+zipcode,city,state))
75
76 for url in urls:
77 api.update_status(status="ZipCodes Of City "+url[1]+", State "+url[2]+" : "+url[0])
78 print url[0]
79 time.sleep(30)
80
81if __name__ == '__main__':
82 tweeter_zipcodes()