Advertisement
alexarcan

Lab6 MS (first 3 ex)

Mar 29th, 2016
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.06 KB | None | 0 0
  1. from twython import TwythonStreamer
  2.  
  3.  
  4. class NearbyTwythonStreamer(TwythonStreamer):
  5.  
  6.         def __init__(self, nearby, api_key, api_secret, token_key, token_secret):
  7.  
  8.                 super(NearbyTwythonStreamer, self).__init__(app_key=api_key,
  9.                         app_secret=api_secret,
  10.                         oauth_token=token_key,
  11.                         oauth_token_secret=token_secret)
  12.                 self.nearby = nearby
  13.  
  14.         def on_success(self, data):
  15.                 if 'text' in data:
  16.                         print data['text']
  17.  
  18.         def on_error(self, status_code, data):
  19.                 print status_code
  20.  
  21.         def find_nearby(self):
  22.                 self.statuses.filter(track=self.nearby)
  23.  
  24.  
  25.  
  26. CONSUMER_KEY = 'Yzf9jCeH1mL824fTbaFBZsHYb'
  27.  
  28. CONSUMER_SECRET = 'BROhZsmMD36RxVWHuW92S1EUMlOHR1QYcuF6cjoArmbn6oE5ur'
  29.  
  30. TOKEN_KEY = '714807114397519872-dP9H2hPDFS5lc6R9OIImAuxsNBe8RqM'
  31.  
  32. TOKEN_SECRET = 'AbNTR1s8fiR7uQ7XTAMQXRGZQrX4Yr4OgWRcesvb7InwX'
  33.  
  34. nearby_search = '#iotupttm2016'
  35.  
  36.  
  37.  
  38. streamer = NearbyTwythonStreamer(nearby_search,
  39.                                 CONSUMER_KEY,
  40.                                 CONSUMER_SECRET,
  41.                                 TOKEN_KEY,
  42.                                 TOKEN_SECRET)
  43.  
  44. streamer.find_nearby()
  45.  
  46. #------------------------------------------
  47.  
  48. from twython import Twython
  49. from time import gmtime, strftime
  50. import RPi.GPIO as GPIO
  51. import time
  52. from datetime import datetime
  53.  
  54.  
  55. GPIO.setmode(GPIO.BOARD)
  56. GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  57.  
  58.  
  59. CONSUMER_KEY = 'Yzf9jCeH1mL824fTbaFBZsHYb'
  60. CONSUMER_SECRET = 'BROhZsmMD36RxVWHuW92S1EUMlOHR1QYcuF6cjoArmbn6oE5ur'
  61. TOKEN_KEY = '714807114397519872-dP9H2hPDFS5lc6R9OIImAuxsNBe8RqM'
  62. TOKEN_SECRET = 'AbNTR1s8fiR7uQ7XTAMQXRGZQrX4Yr4OgWRcesvb7InwX'
  63.  
  64. twitter_api = Twython(CONSUMER_KEY, CONSUMER_SECRET, TOKEN_KEY, TOKEN_SECRET)
  65.  
  66. while True:
  67.         state = GPIO.input(18)
  68.         print(state)
  69.         if state == False:
  70.                 print('twitting!')
  71.                 current_time = str(datetime.now())
  72.                 tweet_text = '#iotupttm2016 Time is:' + current_time
  73.                 twitter_api.update_status(status=tweet_text)
  74.                 break
  75.         time.sleep(2)
  76.  
  77. GPIO.cleanup()
  78.  
  79. #------------------------------------------------------------
  80.  
  81.  
  82. import requests
  83. from pprint import pprint
  84. import RPi.GPIO as GPIO
  85. import time
  86.  
  87.  
  88. GPIO.setmode(GPIO.BOARD)
  89.  
  90. BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
  91.  
  92. API_KEY = "1cf4d48d44ddee920efe3ecd6bd8280d"
  93. city = 'Timisoara'
  94.  
  95. query_params = {'APPID': API_KEY, 'q': city}
  96.  
  97. response = requests.get(BASE_URL, params=query_params)
  98. json_response = response.json()
  99.  
  100. pprint(json_response)
  101. cloud_percentage = json_response['clouds']['all']
  102. temperature = json_response['main']['temp']
  103. temp_celsius = temperature - 273.15
  104.  
  105.  
  106. GPIO.setup(12, GPIO.OUT)
  107.  
  108. if temp_celsius > 2:
  109.         print 'Temperature is rising!'
  110.  
  111.         GPIO.output(12,True)
  112.  
  113.         time.sleep(5)
  114.         GPIO.output(12, False)
  115.  
  116. else:
  117.         print 'Sky is clear.'
  118.  
  119.  
  120.  
  121. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement