forked from Tarun-yadav777/Agmarknet_data_extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
51 lines (36 loc) · 1.44 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import logging
from selenium import webdriver
import configparser
import pandas as pd
from datetime import datetime, date, timedelta
import sys
import os
from modules.extractor import extract
from modules.commodities import commodities
log = logging.getLogger(__name__)
def dateRange(start_date, end_date):
for n in range(int((end_date - start_date).days) + 1):
yield start_date + timedelta(n)
def saveAgMarknetData(driver, commodity_name, commodity_number, from_date, to_date):
df = extract(driver, commodity_name, commodity_number, from_date, to_date)
log.info("Length of Final DF : {}".format(len(df)))
df.to_csv(f"{commodity_number}.csv")
def main():
config = configparser.ConfigParser()
driver = webdriver.Firefox()
for commodity in commodities:
try:
print("Commodity : {}".format(commodity))
fromDateStr = "01-01-2010"
toDateStr = "11-12-2022"
fromDate = datetime.strptime(fromDateStr, "%d-%m-%Y").date()
toDate = datetime.strptime(toDateStr, "%d-%m-%Y").date()
fromDate = datetime.strftime(fromDate, "%d-%b-%Y")
toDate = datetime.strftime(toDate, "%d-%b-%Y")
saveAgMarknetData(driver, commodity["name"], commodity["value"], fromDate, toDate)
except Exception as error:
logging.exception("Exception Thrown in Main App.py")
driver.quit()
if __name__ == "__main__":
main()