Skip to content

Instantly share code, notes, and snippets.

@steevp
Last active December 28, 2019 17:20
Show Gist options
  • Save steevp/511888530967f4d3fabe882c4d00575a to your computer and use it in GitHub Desktop.
Save steevp/511888530967f4d3fabe882c4d00575a to your computer and use it in GitHub Desktop.
Checks for new GOG Connect games
#!/usr/bin/env python2
# Script to check for new GOG Connect games
#
# Configure your system for sending emails first. I used:
# https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay/
import requests
import browsercookie
import json
import smtplib
from email.mime.text import MIMEText
# Fill in your email here
EMAIL = ""
session = requests.Session()
session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0"
# Load cookies from Firefox
session.cookies = browsercookie.firefox()
# Uncomment for Chrome
#session.cookies = browsercookie.chrome()
user_data = json.loads(session.get("https://www.gog.com/userData.json").text)
# Refresh Steam products
refresh_url = "https://www.gog.com/api/v1/users/{}/gogLink/steam/synchronizeUserProfile".format(
user_data["userId"]
)
session.get(refresh_url)
steam_products_url = "http://www.gog.com/api/v1/users/{}/gogLink/steam/exchangeableProducts".format(
user_data["userId"]
)
steam_products = json.loads(session.get(steam_products_url).text)
games_available = False
for key, value in steam_products["items"].items():
if value["status"] == "available":
games_available = True
break
if games_available:
print("New games available!")
msg = MIMEText("Redeem them here:\nhttps://gog.com/connect/")
msg["Subject"] = "New GOG Connect games available!"
msg["From"] = EMAIL
msg["To"] = EMAIL
s = smtplib.SMTP("localhost")
s.sendmail(EMAIL, [EMAIL], msg.as_string())
s.quit()
else:
print("No new games available")
@mt7479
Copy link

mt7479 commented Mar 18, 2018

Any hints on how to get the script working again ? It seems it's current not possible to decode the json object:

Traceback (most recent call last):
  File "./gog-notify.py", line 23, in <module>
    user_data = json.loads(session.get("https://www.gog.com/userData.json").text)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Also, using firefox is currently not working:

('Firefox session filename does not exist:', '/home/user/.mozilla/firefox/oeqmcipd.normale/sessionstore.js')

but that looks to be an upstream bug:

https://bitbucket.org/richardpenman/browsercookie/issues/14/sessionstorejs-does-not-exist-if-firefox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment