Skip to content

Instantly share code, notes, and snippets.

@peterkodermac
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkodermac/f2100768211ebc5f6a65 to your computer and use it in GitHub Desktop.
Save peterkodermac/f2100768211ebc5f6a65 to your computer and use it in GitHub Desktop.
Scrape Google Developer console
# -*- coding: utf-8 -*-
import mechanize
from datetime import date
import datetime
import zipfile
import os
import glob
import subprocess
import time
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_equiv(False)
#robots are disallowed, so lets pretend we're not a robot
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
#get current date in a specific format
d=datetime.date.today()
day= '{:02d}'.format(d.month)
#open url, select correct form and log in
result=br.open("https://play.google.com/apps/publish/bulkreports/download?period="+str(d.year)+"_"+day+"&report_type=STATS_INSTALLS&package=com.example.application&dev_acc=04804029328677663823")
br.form = list(br.forms())[0]
br.form["Email"]="YOUR@DEVELOPER.EMAIL"
br.form["Passwd"]="YourPassword"
result=br.submit().read()
#save the zip file and extract it
file_ = open('result.zip', 'w')
file_.write(result)
file_.close()
zip=zipfile.ZipFile("result.zip")
zip.extractall("/home/peter/production/scrape")
direct_output = subprocess.check_output("tail -2 /home/peter/production/scrape/*overview.csv | cut -d , -f 3", shell=True)
total_installs=subprocess.check_output("tail -2 /home/peter/production/scrape/*overview.csv | cut -d , -f 8", shell=True)
print "Date of scraping: "+time.strftime("%d/%m")+" Number of people using this application "+str(direct_output)+" Total installs "+total_installs
#delete all extracted csv files afterwards
os.system("rm /home/peter/production/scrape/*.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment