Skip to content

Instantly share code, notes, and snippets.

@misgeatgit
Last active December 27, 2018 17:21
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 misgeatgit/29bdefe45c5adcdb8c6a9666602af5b9 to your computer and use it in GitHub Desktop.
Save misgeatgit/29bdefe45c5adcdb8c6a9666602af5b9 to your computer and use it in GitHub Desktop.
import datetime
import time
import urllib2
from BeautifulSoup import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3'}
import time
while True:
req = urllib2.Request(url="https://www.ethiopiatrustfund.org/", headers=headers)
html = urllib2.urlopen(req).read()
soup = BeautifulSoup(html)
# Extract the div which contains the amount
inner_div = soup.findAll("div", {"class": "give-totals-shortcode-wrap"})
# Extract the amount
current_amount = int(inner_div[0].text.split(';')[1].encode('ascii','ignore').replace(',',''))
current_time = datetime.datetime.now()
# Append current record to a file called edtf_stat.csv
line = str(current_time) +","+str(current_amount)
with open("edtf_stat.csv", "a") as f:
f.write(line + "\n")
print("Saved " + line + "\n");
time.sleep(5*60) # Log every 5 minute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment