import requests
import time
from datetime import date
from datetime import timedelta
import zipfile
import urllib

import os.path
import os
import pandas as pd


def scraper(mode):
    
    url = 'https://monitoring.eanet.asia/document/menu/index#publicData'
    download_url = 'https://www.eanet.asia/wp-content/uploads/2024/01/Site_Information_Acid_Deposition_Monitoring_NMP2023_1117.xlsm'
    download_location = "/esarchive/obs/ghost/EANET/metadata/network_provided/"
    today = date.today().strftime('%Y%m%d') #+ timedelta(days = 1)).strftime('%Y%m%d') # problem with timezones???

    """
    Headers = {'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'}

    r = requests.get(download_url, timeout=120, headers=Headers)
    print(r.status_code)
    if r.status_code == 200:
        urllib.request.urlretrieve(url, download_location+"downloaded_metadata.xlsm")
        print('Downloaded metadata')
    else:
        print('url status not ok')"""

    # open file
    metadata = pd.read_excel(download_location+"downloaded_metadata.xlsm", engine='pyxlsb').fillna('')
    print(metadata)
