Skip to content

Instantly share code, notes, and snippets.

@conradev
Created May 19, 2012 17:07
Show Gist options
  • Save conradev/2731539 to your computer and use it in GitHub Desktop.
Save conradev/2731539 to your computer and use it in GitHub Desktop.
Cydia Store Daily Report
#!/usr/bin/python
import string, time, calendar, hashlib, urllib2, smtplib
from email.mime.text import MIMEText
# Cydia globals
product_ids = ['org.thebigboss.somepackage', 'org.thebigboss.someotherpackage']
splits = [ 0.70, 0.35 ]
vendor_id = ""
vendor_secret = ""
# SMTP globals
smtp_server = "smtp.gmail.com"
smtp_username = "[email protected]"
smtp_password = "password"
smtp_email = smtp_username
def main():
vendor_hash = hashlib.md5()
vendor_hash.update(vendor_id)
vendor_hash.update(vendor_secret)
vendor_hash = vendor_hash.hexdigest()
money_made = 0.00
time_cutoff = time.time() - (24 * 60 * 60)
for (product_id, split) in zip(product_ids, splits):
failureCount = 0
while True:
try:
transactions = urllib2.urlopen('http://cydia.saurik.com/api/roster?package=' + product_id + '&vendor-hash=' + vendor_hash)
except:
failureCount += 1
if failureCount >= 5:
raise
else:
break
transaction = transactions.readline()
while transaction:
pieces = transaction.split(" ")
price = float(pieces[8]) * split
date = string.join(pieces[3:5], " ")
date = date.split(".")
date = string.join(date[:1])
date = time.strptime(date, "%Y-%m-%d %H:%M:%S")
if calendar.timegm(date) > time_cutoff:
money_made += price
else:
break
transaction = transactions.readline()
money_made = '%.2f' % money_made
msg = MIMEText("You made $" + money_made + " from the Cydia Store yesterday.")
msg['Subject'] = "Cydia Store Report"
msg['From'] = smtp_email
msg['To'] = smtp_email
smtp_client = smtplib.SMTP_SSL(smtp_server, 465)
smtp_client.login(smtp_username, smtp_password)
smtp_client.sendmail(smtp_email, [smtp_email], msg.as_string())
smtp_client.quit()
if __name__ == "__main__":
main()
@kylehowells
Copy link

Took me ages to work out why this gives wrong results in my emails. It doesn't take account of Cydia's 30%.

I fixed it in my fork: https://gist.github.com/freerunnering/d575888e15a27c25ca58

Also: thanks for this! I've had this set to run every morning for a few years now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment