Advertisement
Guest User

Cat facts

a guest
Jul 27th, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | None | 0 0
  1. import json
  2. import time
  3. from random import randrange
  4. from urllib2 import Request, urlopen
  5.  
  6. V2TOKEN = 'INSERT TOKEN HERE'
  7. ROOMID = 2962592
  8.  
  9. catFacts = [
  10.     "The average cat sleeps 16-18 hours per day.",
  11.     "Cats and humans have been associated for nearly 10000 years.",
  12.     "A group of cats is called a clowder, a male cat is called a tom, a female cat is called a molly or queen while young cats are called kittens.",
  13.     "Older cats can at times act aggressively towards kittens.",
  14.     "On average cats live for around 12 to 15 years.",
  15.     "Cats spend a large amount of time licking their coats to keep them clean.",
  16.     "Feral cats are often seen as pests and threats to native animals.",
  17.     "The heaviest domestic cat on record is 21.297 kilograms (46 lb 15.2 oz).",
  18.     "The group of words associated with cat (catt, cath, chat, katze) stem from the Latin catus, meaning domestic cat, as opposed to feles, or wild cat",
  19.     "Approximately 40,000 people are bitten by cats in the U.S. annually.",
  20.     "According to Hebrew legend, Noah prayed to God for help protecting all the food he stored on the ark from being eaten by rats. In reply, God made the lion sneeze, and out popped a cat.",    
  21.     "Most cats give birth to a litter of between one and nine kittens. The largest known litter ever produced was 19 kittens, of which 15 survived."
  22. ]
  23.  
  24.  
  25. # API V2, send message to room:
  26. url = 'https://api.hipchat.com/v2/room/%d/notification' % ROOMID
  27. #message = "Cats are the most popular pet in the United States: There are 88 million pet cats and 74 million dogs"
  28.  
  29. headers = {
  30.     "content-type": "application/json",
  31.     "authorization": "Bearer %s" % V2TOKEN}
  32.  
  33.  
  34. def postFact():
  35.     randIndex = randrange(0, len(catFacts))
  36.     message = catFacts[randIndex]
  37.  
  38.  
  39.     datastr = json.dumps({
  40.         'message': message,
  41.         'color': 'yellow',
  42.         'message_format': 'html',
  43.         'notify': False})
  44.  
  45.     request = Request(url, headers=headers, data=datastr)
  46.     uo = urlopen(request)
  47.     rawresponse = ''.join(uo)
  48.     uo.close()
  49.     assert uo.code == 204
  50.  
  51. if __name__ == '__main__':
  52.     while True:
  53.         postFact()
  54.         time.sleep(600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement