Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twython import TwythonStreamer
- class NearbyTwythonStreamer(TwythonStreamer):
- def __init__(self, nearby, api_key, api_secret, token_key, token_secret):
- super(NearbyTwythonStreamer, self).__init__(app_key=api_key,
- app_secret=api_secret,
- oauth_token=token_key,
- oauth_token_secret=token_secret)
- self.nearby = nearby
- def on_success(self, data):
- if 'text' in data:
- print data['text']
- def on_error(self, status_code, data):
- print status_code
- def find_nearby(self):
- self.statuses.filter(track=self.nearby)
- CONSUMER_KEY = 'Yzf9jCeH1mL824fTbaFBZsHYb'
- CONSUMER_SECRET = 'BROhZsmMD36RxVWHuW92S1EUMlOHR1QYcuF6cjoArmbn6oE5ur'
- TOKEN_KEY = '714807114397519872-dP9H2hPDFS5lc6R9OIImAuxsNBe8RqM'
- TOKEN_SECRET = 'AbNTR1s8fiR7uQ7XTAMQXRGZQrX4Yr4OgWRcesvb7InwX'
- nearby_search = '#iotupttm2016'
- streamer = NearbyTwythonStreamer(nearby_search,
- CONSUMER_KEY,
- CONSUMER_SECRET,
- TOKEN_KEY,
- TOKEN_SECRET)
- streamer.find_nearby()
- #------------------------------------------
- from twython import Twython
- from time import gmtime, strftime
- import RPi.GPIO as GPIO
- import time
- from datetime import datetime
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- CONSUMER_KEY = 'Yzf9jCeH1mL824fTbaFBZsHYb'
- CONSUMER_SECRET = 'BROhZsmMD36RxVWHuW92S1EUMlOHR1QYcuF6cjoArmbn6oE5ur'
- TOKEN_KEY = '714807114397519872-dP9H2hPDFS5lc6R9OIImAuxsNBe8RqM'
- TOKEN_SECRET = 'AbNTR1s8fiR7uQ7XTAMQXRGZQrX4Yr4OgWRcesvb7InwX'
- twitter_api = Twython(CONSUMER_KEY, CONSUMER_SECRET, TOKEN_KEY, TOKEN_SECRET)
- while True:
- state = GPIO.input(18)
- print(state)
- if state == False:
- print('twitting!')
- current_time = str(datetime.now())
- tweet_text = '#iotupttm2016 Time is:' + current_time
- twitter_api.update_status(status=tweet_text)
- break
- time.sleep(2)
- GPIO.cleanup()
- #------------------------------------------------------------
- import requests
- from pprint import pprint
- import RPi.GPIO as GPIO
- import time
- GPIO.setmode(GPIO.BOARD)
- BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
- API_KEY = "1cf4d48d44ddee920efe3ecd6bd8280d"
- city = 'Timisoara'
- query_params = {'APPID': API_KEY, 'q': city}
- response = requests.get(BASE_URL, params=query_params)
- json_response = response.json()
- pprint(json_response)
- cloud_percentage = json_response['clouds']['all']
- temperature = json_response['main']['temp']
- temp_celsius = temperature - 273.15
- GPIO.setup(12, GPIO.OUT)
- if temp_celsius > 2:
- print 'Temperature is rising!'
- GPIO.output(12,True)
- time.sleep(5)
- GPIO.output(12, False)
- else:
- print 'Sky is clear.'
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement