Advertisement
Guest User

Untitled

a guest
Jul 10th, 2016
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import datetime
  2. import requests
  3. import sqlite3
  4. import json
  5.  
  6. url = "https://sports.ladbrokes.com/en-gb/events/type/football/euro-2016/euro-2016-outrights"
  7.  
  8. timestamp = datetime.datetime.now().isoformat()
  9. source = requests.get(url)
  10. print("source response is {}".format(source))
  11. source.raise_for_status()
  12.  
  13. with open("/home/pawel/euro/backups/{}".format(timestamp), "wb") as f:
  14.     # Keep backup of raw response in case something breaks and I need to debug it or
  15.     # if I need to reprocess data again.
  16.     f.write(source.text.encode("utf8"))
  17.  
  18. data = source.json()
  19. bets = data["outrightEvents"][0]["markets"][0]["selections"]
  20.  
  21. with sqlite3.connect("/home/pawel/euro/euro.db") as con:
  22.     print("saving to db...")
  23.     for bet in bets:
  24.         name = bet["nameRaw"]
  25.         lastUpdate = bet["lastUpdatedTime"]
  26.         odds = bet["primaryPrice"]
  27.         fractional = odds["fractionalOdds"]
  28.         decimal_odds = odds["decimalOdds"]
  29.         con.execute("INSERT INTO bets(updated_ladbrokes, registered_db, team_name, decimal_odds, fractional_odds) VALUES (?, ?, ?, ?, ?);",
  30.                     (lastUpdate, timestamp, name, decimal_odds, fractional))
  31.         con.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement