Last active
August 29, 2015 14:06
-
-
Save copeland3300/5cd1fb76814c8e2f06a9 to your computer and use it in GitHub Desktop.
This file contains 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 characters
''' | |
referenced pages | |
http://stackoverflow.com/questions/845058/how-to-get-line-count-cheaply-in-python | |
''' | |
import argparse | |
import sys | |
import requests | |
import simplejson | |
from mailer import Mailer, Message | |
import time | |
URL = 'http://store.steampowered.com/api/appdetails/?appids=' | |
FROM_ADDR = 'copeland3300@yahoo.com' | |
TO_ADDR = ['copeland3300+pythonmessage@gmail.com'] | |
def send_email(msg): | |
''' | |
Sends the provided message to global recipients | |
''' | |
# change the server and port to match what you want | |
sender = Mailer('smtp.mail.yahoo.com', port=587, use_tls=True) | |
sender.login(FROM_ADDR, '') | |
sender.send(msg) | |
def create_message(subject, body): | |
''' | |
Returns a MIME message for sending | |
''' | |
msg = Message() | |
msg.From = FROM_ADDR | |
msg.To = TO_ADDR | |
msg.Subject = subject | |
msg.Body = body | |
return msg | |
def get_game_info(appid): | |
''' | |
Returns a dictionary of info about specified game | |
''' | |
aid = str(appid) | |
info = {} | |
req = requests.get(URL + str(aid)) | |
if req.json()[aid]['success'] == True: | |
return req.json()[aid]['data']['name'], aid | |
else: | |
return 'none', aid | |
#return 'nunya', 100 | |
def main(): | |
''' | |
The main function obviously | |
''' | |
#args = get_args() | |
#if not args.appid: | |
#print 'Please specify a game ID' | |
#sys.exit(1) | |
stats = [] | |
starttime = time.time() | |
outfile = open('data.txt', 'w') | |
for i in range(50,100): | |
info, gid = get_game_info(i) | |
if info != 'none': | |
#print gid, info | |
outfile.write(gid + ' ' + info) | |
outfile.write('\n') | |
outfile.close() | |
tooktime = time.time() - starttime | |
stats.append('Time taken to scrape: ' + str(tooktime)) | |
stats.append('Number of Items: ' + str(sum(1 for line in open('data.txt', 'r')))) | |
send_email(create_message('done scraping', '\n'.join(stats))) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment