Guest User

Untitled

a guest
Jun 24th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. import praw
  2. import json
  3. import requests
  4. import tweepy
  5. import time
  6.  
  7. access_token = ['3319047260-hYs0OiGb1uvurlm0HUXIyTKKFjmJL7hIs1MfblX','3319731960-fL63tqQGoIfmMPzzSyELBMy89dcpp5IfVciiILj']
  8. access_token_secret = ['ehPksk8oAl7k0oMaJVm4ouzGrmSwpphb57O6cvBTjXCWr','HlCTmIMyNylBIMU3jPyvNbb0ryb3Du70WRTFbpBsgNSfG']
  9. consumer_key = ['rTkDstUS2cEVfo1WA9ih9uHJ5','w2NRYFX4grBVJYNULE0V0m3mL']
  10. consumer_secret = ['WpzXZq7s0q18rpypeWZTMfJG3zTINJkeNeGnEtLHoRL3n3Ek6L','WNWTCmUZ2AMNQp74Tbv1xsCgylPvG9v7jaVHx6XGCegv0Bj0tV']
  11.  
  12.  
  13. import MySQLdb,json,datetime
  14. import requests
  15. # configuration
  16. DATABASE = 'zipStreet'
  17. DB_SERVER = 'localhost'
  18. DEBUG = True
  19. SECRET_KEY = 'epicMedia123'
  20. USERNAME = 'root'
  21. PASSWORD = 'babamanohar'
  22.  
  23. #Mysql Connection Declaration
  24. db = MySQLdb.connect(DB_SERVER,USERNAME,PASSWORD,DATABASE)
  25. db.autocommit(True)
  26. cursor = db.cursor()
  27.  
  28. #Redis Declaration
  29.  
  30. import redis
  31.  
  32. redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
  33.  
  34. def 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.  
  44. def 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.  
  63. def 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.  
  81. if __name__ == '__main__':
  82.     tweeter_zipcodes()
Add Comment
Please, Sign In to add comment