Skip to content

Instantly share code, notes, and snippets.

@Freelix Freelix/steamgifts.py
Last active Aug 24, 2017

Embed
What would you like to do?
Generate .exe program to parse Steamgifts.com to have a chance to win Steam games based on your wishlist
import queue
import requests
import urllib3
from bs4 import BeautifulSoup
STEAM_GIFTS_URL = "https://www.steamgifts.com/giveaways/search?type=wishlist"
USER_AGENT = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"
POST_URL = "https://www.steamgifts.com/ajax.php"
COOKIE = {
'PHPSESSID': 'needs to be replaced with your PHPSESSID'
}
def executeQuery(url, header):
result = requests.get(url, headers=header, cookies=COOKIE)
result.raise_for_status()
result.encoding = "utf-8"
content = result.content
soup = BeautifulSoup(content, "html.parser")
xsrf_token = soup.find_all("input", {"name": "xsrf_token", "type": "hidden"})[
0].get('value')
game_code = get_game_code_from_url(url)
data = {
"xsrf_token": xsrf_token,
"do": "entry_insert",
"code": game_code
}
header = {
'Accept': 'application/json, text/javascript',
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': USER_AGENT
}
print("Entering giveaway " + url)
requests.post(POST_URL, data=data, headers=header, cookies=COOKIE)
def get_game_code_from_url(url):
start = "/giveaway/"
end = "/"
return url[url.find(start) + len(start):url.rfind(end)]
def main():
header = {
'Accept-Encoding': 'identity',
'User-Agent': USER_AGENT
}
result = requests.get(STEAM_GIFTS_URL, headers=header, cookies=COOKIE)
result.raise_for_status()
content = result.content
soup = BeautifulSoup(content, "html.parser")
links = soup.find_all("a", "giveaway__heading__name")
for element in links:
pinned = element.find_parent("div", "pinned-giveaways__outer-wrap")
if pinned is None:
try:
url = STEAM_GIFTS_URL + element.attrs['href']
executeQuery(url, header)
except IndexError:
print('Error with ' + url)
if __name__ == "__main__":
main()
# -*- mode: python -*-
block_cipher = None
a = Analysis(['steamgifts.py'],
pathex=['D:\\git\\your_folder'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz, Tree('..\\your_folder\\'),
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='Steamgifts',
debug=False,
strip=False,
upx=True,
console=True)
1- Install dependencies
---------------------
You must first install python !
Once it it installed, run those commands
pip install beautifulsoup4
pip install requests
pip install urllib3
pip install pyinstaller
2- Replace the COOKIE constant
-------------------------------
[This example is on Chrome, but you can use any browser]
1- Log in to your account on steamgifts.com
2- Open the developper tool
3- Click on the Application tab, then on Cookies on the left. Select htts://www.steamgifts.com
4- Locate the cookie name PHPSESSID and copy the value associated with this one
5- Paste it in the steamgifts.py (replace the text 'needs to be replaced with your PHPSESSID')
3- Replace the path in steamgifts.spec
---------------------------------------
1- Replace the path on the line
"pathex=['D:\\git\\your_folder'],"
with the absolute path of your folder containing both files.
2- Replace the name of the folder on the line
"exe = EXE(pyz, Tree('..\\your_folder\\'),"
with the name of your folder.
4- Create the .exe
-------------------
pyinstaller steamgifts.spec
5- Run the app
---------------
The application will now be generated as a standalone app in the dist folder of the safe directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.