Steam Automation Script
Steam Automation Script
Steam game trading is a big market on Steam. It is a tedious process and required about 10-15 hours of
work a week for those who wish to trade their games. The process requires one to repeatedly interact
with the browser through forms and extract links from their e-mails. Thus, in the summer of 2014 I
decided to write a Python script to automate this process by parsing and interacting with my e-mail and
browser. After writing this script, I open sourced it and sent it to many game traders to assist their game
trading business and save them hundreds of hours of manual labor.
This project has allowed me to gain a significant amount of software experience. To parse and
communicate with the webpage I used a Selenium WebDriver. I looked for the “id” attributes of the
forms and buttons in the webpages HTML. After retrieving these attributes, I used Selenium to interact
with these elements. For username and password input, I used the Tkinter GUI package to hide the
user’s password input. Finally, I used the imaplib module to login and parse my e-mails. This allowed me
to extract the authentication codes required to log into Steam and also the gift links for the game.
Because it is difficult to explain exactly what my code does, I have created this portfolio. The following is
a set of screenshots explaining exactly what my script does followed by the source code.
1. Display GUI to input username and passwords using the Tkinter GUI package
My code uses the Selenium WebDriver to access different forms based on the id of the form in the
webpage’s HTML.
3. Parses e-mail for authentication code to log in
Upon attempting to log in, Steam will send an e-mail with an authentication code as a way to guard
against account theft. My script opens this e-mail and parses it for the authentication code.
It then goes back to the webpage and inputs the authentication code.
4. Accesses JSON data and parses it on the webpage with regular expressions
Using the Selenium WebDriver, I can access the games in my inventory and grab their JSON formatted
data. I can parse this to find out which games I want to send.
5. Extract the JSON data to access each game and send it to my e-mail
From the JSON data, I extracted links for all the games and looped through my game inventory until I
sent all the games to my e-mail.
6. Parse the game gift links in my e-mail and extract the links into text files.
After the games are sent to my e-mail I can extract the links by parsing the contents of the e-mails.
The parsed game links are organized in folders by the date in which they were extracted as seen in
section 1 of the image above. They are also organized by the name of the game as seen in section 2.
Finally, the links can be found in the text file as seen in section 3.
Source Code to Interact with Browser
import sys
import getpass
import imaplib
import os
import time
import re
import itertools
# button widget
self.steamUserW = Entry(self.master)
self.steamPassW = Entry(self.master, show="*")
self.emailPassW = Entry(self.master, show="*")
self.submit = Button(self.master, text="Submit", command=self.assign)
# grabs the values in the entry boxes and assigns them to variable
def assign(self, *args):
self.steamUser = self.steamUserW.get()
self.steamPass = self.steamPassW.get()
self.emailPass = self.emailPassW.get()
self.close()
root = Tk()
userGui = gui(root)
root.mainloop()
steamUser = userGui.steamUser
steamPass = userGui.steamPass
emailPass = userGui.emailPass
# parses email, creates folder, creates text file and appends steam gift
link to text file
for i in range(len(id_list)):
# get e-mail body text
result, data = M.fetch(id_list[i], "(RFC822)")
specialCode = None
while specialCode == None:
specialCode = process_mailbox() # ... do something with emails, see below
...
time.sleep(5)
# used to parse e-mail for game gift links and organize into folders
def process_mailbox(M):
rv, data = M.search(None,'(UNSEEN)')
# parses email, creates folder, creates text file and appends steam gift
link to text file
for i in range(len(id_list)):
# get e-mail body text
result, data = M.fetch(id_list[i], "(RFC822)")
f.close()
M = imaplib.IMAP4_SSL('imap.gmail.com')
M.login('sweetkeys.steam@gmail.com', emailPass)