Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import requests
- import sqlite3
- import json
- url = "https://sports.ladbrokes.com/en-gb/events/type/football/euro-2016/euro-2016-outrights"
- timestamp = datetime.datetime.now().isoformat()
- source = requests.get(url)
- print("source response is {}".format(source))
- source.raise_for_status()
- with open("/home/pawel/euro/backups/{}".format(timestamp), "wb") as f:
- # Keep backup of raw response in case something breaks and I need to debug it or
- # if I need to reprocess data again.
- f.write(source.text.encode("utf8"))
- data = source.json()
- bets = data["outrightEvents"][0]["markets"][0]["selections"]
- with sqlite3.connect("/home/pawel/euro/euro.db") as con:
- print("saving to db...")
- for bet in bets:
- name = bet["nameRaw"]
- lastUpdate = bet["lastUpdatedTime"]
- odds = bet["primaryPrice"]
- fractional = odds["fractionalOdds"]
- decimal_odds = odds["decimalOdds"]
- con.execute("INSERT INTO bets(updated_ladbrokes, registered_db, team_name, decimal_odds, fractional_odds) VALUES (?, ?, ?, ?, ?);",
- (lastUpdate, timestamp, name, decimal_odds, fractional))
- con.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement