Last active
October 25, 2024 20:26
-
-
Save anne17/c00c2d0259de076f1ff4888f4176cbcb to your computer and use it in GitHub Desktop.
Revisions
-
anne17 revised this gist
Apr 14, 2023 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ from datetime import datetime import urllib from dateutil.tz import tzlocal import requests @@ -26,8 +24,8 @@ def get_from_epic(): for offer in game.get("promotions", {}).get("promotionalOffers", []): for promo in offer.get("promotionalOffers"): # Check if promo is valid enddate = datetime.strptime(promo.get("endDate"), "%Y-%m-%dT%H:%M:%S.%f%z") startdate = datetime.strptime(promo.get("startDate"), "%Y-%m-%dT%H:%M:%S.%f%z") is_valid = enddate >= now >= startdate is_free = promo.get("discountSetting", {}).get("discountPercentage", -1) == 0 if is_valid and is_free: @@ -55,7 +53,7 @@ def get_from_steam(freegames): print(gamedict["title"]) print(resp.content) print() # TODO: parse html, e.g. with beautifulsoup (https://beautiful-soup-4.readthedocs.io/en/latest/) to get the first hit, get its ID from "data-ds-appid" # TODO: make get request for STEAM_CHECK_GAME % ID and get reviews etc and store it in freegames dict @@ -68,8 +66,10 @@ def send_email(body): # TODO: do something like in https://github.com/anne17/bevaka-tandvard/blob/main/bevakning.py#L125 if __name__ == "__main__": freegames = get_from_epic() get_from_steam(freegames) # TODO: do some stuff to avoid multiple notifications for the same games email_body = build_email_body(freegames) send_email(email_body) -
anne17 created this gist
Apr 13, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ from datetime import datetime import urllib from dateutil.parser import isoparse from dateutil.tz import tzlocal import requests EPIC_SEARCH_URL = "https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=en-US&country=SE&allowCountries=SE" STEAM_SEARCH_URL = "https://store.steampowered.com/search/suggest?term=%s&f=games&cc=SE&realm=1&l=english&use_search_spellcheck=1" STEAM_CHECK_GAME = 'https://api.steampowered.com/IStoreBrowseService/GetItems/v1?input_json={"ids":[{"appid":%s}],"context":{"language":"english","country_code":"SE","steam_realm":1},"data_request":{"include_reviews":true,"include_basic_info":true}}' def get_from_epic(): """Get free games from epic""" freegames = [] now = datetime.now(tzlocal()) resp = requests.get(EPIC_SEARCH_URL) # TODO: error handling in case request fails json_data = resp.json() for game in json_data.get("data", {}).get("Catalog", {}).get("searchStore", {}).get("elements", []): if game.get("promotions"): for offer in game.get("promotions", {}).get("promotionalOffers", []): for promo in offer.get("promotionalOffers"): # Check if promo is valid enddate = isoparse(promo.get("endDate")) startdate = isoparse(promo.get("startDate")) is_valid = enddate >= now >= startdate is_free = promo.get("discountSetting", {}).get("discountPercentage", -1) == 0 if is_valid and is_free: fg = {"title": game.get("title", "")} fg["image"] = game.get("keyImages", [{}])[0].get("url", "") freegames.append(fg) return freegames def get_from_steam(freegames): """Get info for freegames from Steam.""" # Info från Martin # Man kan använda denna och parsa HTMLen: # https://store.steampowered.com/search/suggest?term=impostor+factory&f=games&cc=SE&realm=1&l=english&use_search_spellcheck=1 # Kolla upp betyg och beskrivning för detta ID: # https://api.steampowered.com/IStoreBrowseService/GetItems/v1?input_json={"ids":[{"appid":1182620}],"context":{"language":"english","country_code":"SE","steam_realm":1},"data_request":{"include_reviews":true,"include_basic_info":true}} for gamedict in freegames: searchstring = urllib.parse.quote(gamedict["title"]) resp = requests.get(STEAM_SEARCH_URL % searchstring) # TODO: error handling in case request fails resp_html = resp.content print(gamedict["title"]) print(resp.content) print() # TODO: parse html, e.g. with beautifulsoup to get the first hit, get its ID from "data-ds-appid" # TODO: make get request for STEAM_CHECK_GAME % ID and get reviews etc and store it in freegames dict def build_email_body(freegames): pass # TODO: build nice email html body def send_email(body): pass # TODO: do something like in https://github.com/anne17/bevaka-tandvard/blob/main/bevakning.py#L125 if __name__ == "__main__": freegames = get_from_epic() get_from_steam(freegames) email_body = build_email_body() send_email(email_body)