Skip to content

Instantly share code, notes, and snippets.

@mentix02
Last active October 7, 2018 13:52
Show Gist options
  • Save mentix02/3986ff5c50c7146a3c95fc57beeff739 to your computer and use it in GitHub Desktop.
Save mentix02/3986ff5c50c7146a3c95fc57beeff739 to your computer and use it in GitHub Desktop.
A file to keep track of an NGO
#!/usr/bin/python3
from time import sleep
from requests import get
from datetime import datetime
from bs4 import BeautifulSoup
URL = "http://www.flutur.org/terms"
counter = 0
underscore = "|-------------------------------|"
money_save = open('./money.txt', 'a+')
last = open('./money.txt', 'r+')
last_money = last.readlines()
if len(str(last_money).strip()) <= 2:
last_money = 0
else:
last_money = last_money[len(last_money) - 1]
last_money = float(last_money[last_money.find('Rs. ')+4:])
last.close()
print(underscore)
try:
while True:
try:
r = get(URL)
# amzn = get('https://www.amazon.in/ref=assoc_aax_fallback_728x90?tag=flutur-21&linkCode=ur8')
except Exception as e:
print("Network error!")
quit()
try:
counter += 1
hit = "|\tHit : " + str(counter) + "\t\t"
print(hit + "\t|") if counter < 10 else print(hit + "|")
print("|\tResponse : " + str(r.status_code) + "\t\t|")
soup = BeautifulSoup(r.text, "lxml")
money = soup.find("div", {"class": "display-number"}).string.strip()
money = money.replace(",", "")
value_money = float(money[money.find('Rs. ')+4:])
print("|\t" + str(money) + "\t\t|")
if value_money != last_money:
profit = str(value_money - last_money)
profit = profit[:6].strip()
print("|\tProfit : " + profit + "\t\t|")
money_save.write(
str(
datetime.now().ctime()
) + " : " + str(money) + "\tProfit : " + profit + "\n"
)
else:
money_save.write(str(datetime.now().ctime()) + " : " + str(money) + "\n")
last_money = value_money
print(underscore)
sleep(5)
except Exception as e:
print(e)
continue
except Exception:
try:
money_save.write(str(datetime.now().ctime()) + " : " + str(money) + "\n")
money_save.close()
print("\nLog saved in money.txt")
print("Bye!")
quit(0)
except Exception:
print("Bye!")
quit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment