Skip to content

Instantly share code, notes, and snippets.

@EspressoCake
Created December 30, 2015 15:25
Show Gist options
  • Save EspressoCake/e378928eddd231e8d242 to your computer and use it in GitHub Desktop.
Save EspressoCake/e378928eddd231e8d242 to your computer and use it in GitHub Desktop.
import pprint
import pywapi
import time
import requests
import json
def hipchatWeatherAPI():
while True:
noaa = pywapi.get_weather_from_weather_com('replace_with_your_zip_code')
rightnow = time.strftime("%H:%M")
temperature = int(float(noaa['current_conditions']['temperature']) * float(9/5) + 32)
generalweather = noaa['current_conditions']['text']
messagesForRoom = ("It is currently " + str(temperature) + "F, and " + str(generalweather).upper() + " as of " + str(rightnow))
room = 'https://hipchat_base_url/v2/room/replace_with_number/notification'
headers = {'Authorization':'Bearer your_api_token', 'Content-type':'application/json'}
requests.post(url = room, data = json.dumps({'message':messagesForRoom, 'color':'random'}), headers = headers, verify=False)
time.sleep(1800)
hipchatWeatherAPI()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment