Skip to content

Instantly share code, notes, and snippets.

@galvanic
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save galvanic/e9627980b40cf6b378c0 to your computer and use it in GitHub Desktop.

Select an option

Save galvanic/e9627980b40cf6b378c0 to your computer and use it in GitHub Desktop.
Parser for potato salad kickstarter funding.
#!/usr/bin/env python
"""
Script parses funding reached by the potato salad kickstarter
through lynx CLI browser.
Appends funding and date and time of funding to CSV file
for later plotting.
"""
import sys, re, csv
import datetime
from commands import getstatusoutput
cmd = 'lynx -dump -crawl "https://www.kickstarter.com/projects/324283889/potato-salad"'
webpage = getstatusoutput(cmd)[1]
funding = re.search(r'\$(\d\d\d?),(\d\d\d)\n\s+pledged of \$10 goal\n', webpage)
funding = int(funding.group(1) + funding.group(2))
backers = re.search(r'(\d\d?),(\d\d\d)\n\s+Backers\n', webpage)
backers = int(backers.group(1) + backers.group(2))
row = (funding, datetime.datetime.now(), backers)
csv_path = sys.argv[1]
with open(csv_path, "a") as ofile:
writer = csv.writer(ofile, delimiter='\t')
writer.writerow(row)
try:
verbose = sys.argv[2]
except IndexError:
verbose = False
if verbose:
print '$%d at' % funding, datetime.datetime.now(), 'by %d backers' % backers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment