Learn practical skills, build real-world projects, and advance your career
# @hidden_cell
# The project token is an authorization token that is used to access project resources like data sources, connections, and used by platform APIs.
from project_lib import Project
import pandas as pd
import requests
import numpy as np
from datetime import datetime
from pytz import timezone
import csv
import time

project = Project(project_id='4f97b1bc-588d-42b9-a2f5-faa9d9186fa6', project_access_token='p-11b8681990cf066e0a5dfa7d6a7ee62087f49636')
pc = project.project_context
Teams = project.get_file("Team_ID.csv")
TeamsDF = pd.read_csv(Teams)
weeks_2013 = project.get_file("2013_Schedule.csv")
weeks_2013_DF = pd.read_csv(weeks_2013)

url_links = weeks_2013_DF["URL"].to_list()

CHECK BEFORE LOAD

# #Create Metadata and write to temp csv file
with open('Tempmeta.csv', 'w') as file:
            wr = csv.writer(file, quoting=csv.QUOTE_ALL)
            header_list = ['game_date', 'link', 'total_tables', 'first_table', 'count_check_wanted_tables','utc_ts', 'status']
            wr.writerow(header_list)
            for link in url_links:
                find_game_date = link.rfind('/20')
                global game_date
                game_date = link[find_game_date+1:find_game_date+9]
                fmt = "%Y-%m-%d %H:%M:%S"

                utc_ts = datetime.now().astimezone(timezone('US/Pacific')).strftime(fmt)
                try:
                    html = requests.get(link).content
                    html = html.decode("utf-8") 
                    html = html.replace("<!--","")
                    tables_all = pd.read_html(html)
                    total_tables = len(tables_all)

                    for index, table in enumerate(tables_all):
                        if table.shape == (2,7):
                            first_table = index
                            global wanted_tables 
                            wanted_tables = tables_all[index:total_tables-1]
                            count_check_wanted_tables = len(wanted_tables)
                            meta =[game_date, link, total_tables, first_table, count_check_wanted_tables,utc_ts, "Pass"]
                            wr.writerow(meta)
                            print(meta)

                except Exception as e:
                    meta =[game_date, link,None,None,None,utc_ts, "Fail"]
                    wr.writerow(meta)
                    print(meta)
['20130905', 'https://www.pro-football-reference.com/boxscores/201309050den.htm', 37, 16, 20, '2019-08-21 17:10:02', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080chi.htm', 37, 16, 20, '2019-08-21 17:10:03', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080clt.htm', 37, 16, 20, '2019-08-21 17:10:04', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080pit.htm', 37, 16, 20, '2019-08-21 17:10:05', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080det.htm', 37, 16, 20, '2019-08-21 17:10:05', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080cle.htm', 37, 16, 20, '2019-08-21 17:10:06', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080buf.htm', 37, 16, 20, '2019-08-21 17:10:07', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080jax.htm', 37, 16, 20, '2019-08-21 17:10:08', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080nor.htm', 37, 16, 20, '2019-08-21 17:10:08', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080nyj.htm', 37, 16, 20, '2019-08-21 17:10:09', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080car.htm', 37, 16, 20, '2019-08-21 17:10:10', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080ram.htm', 37, 16, 20, '2019-08-21 17:10:11', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080sfo.htm', 37, 16, 20, '2019-08-21 17:10:11', 'Pass'] ['20130908', 'https://www.pro-football-reference.com/boxscores/201309080dal.htm', 37, 16, 20, '2019-08-21 17:10:12', 'Pass'] ['20130909', 'https://www.pro-football-reference.com/boxscores/201309090was.htm', 37, 16, 20, '2019-08-21 17:10:13', 'Pass'] ['20130909', 'https://www.pro-football-reference.com/boxscores/201309090sdg.htm', 37, 16, 20, '2019-08-21 17:10:14', 'Pass'] ['20130912', 'https://www.pro-football-reference.com/boxscores/201309120nwe.htm', 37, 16, 20, '2019-08-21 17:10:15', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150rav.htm', 37, 16, 20, '2019-08-21 17:10:16', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150buf.htm', 37, 16, 20, '2019-08-21 17:10:16', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150phi.htm', 37, 16, 20, '2019-08-21 17:10:17', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150clt.htm', 37, 16, 20, '2019-08-21 17:10:18', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150gnb.htm', 37, 16, 20, '2019-08-21 17:10:19', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150kan.htm', 37, 16, 20, '2019-08-21 17:10:19', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150htx.htm', 37, 16, 20, '2019-08-21 17:10:20', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150chi.htm', 37, 16, 20, '2019-08-21 17:10:21', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150atl.htm', 37, 16, 20, '2019-08-21 17:10:22', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150tam.htm', 37, 16, 20, '2019-08-21 17:10:23', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150crd.htm', 37, 16, 20, '2019-08-21 17:10:23', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150nyg.htm', 37, 16, 20, '2019-08-21 17:10:24', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150rai.htm', 37, 16, 20, '2019-08-21 17:10:25', 'Pass'] ['20130915', 'https://www.pro-football-reference.com/boxscores/201309150sea.htm', 37, 16, 20, '2019-08-21 17:10:26', 'Pass'] ['20130916', 'https://www.pro-football-reference.com/boxscores/201309160cin.htm', 37, 16, 20, '2019-08-21 17:10:27', 'Pass'] ['20130919', 'https://www.pro-football-reference.com/boxscores/201309190phi.htm', 37, 16, 20, '2019-08-21 17:10:28', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220dal.htm', 37, 16, 20, '2019-08-21 17:10:28', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220nwe.htm', 37, 16, 20, '2019-08-21 17:10:29', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220car.htm', 37, 16, 20, '2019-08-21 17:10:30', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220nor.htm', 37, 16, 20, '2019-08-21 17:10:31', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220rav.htm', 37, 16, 20, '2019-08-21 17:10:32', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220oti.htm', 37, 16, 20, '2019-08-21 17:10:33', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220cin.htm', 37, 16, 20, '2019-08-21 17:10:33', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220was.htm', 37, 16, 20, '2019-08-21 17:10:34', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220min.htm', 37, 16, 20, '2019-08-21 17:10:35', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220mia.htm', 37, 16, 20, '2019-08-21 17:10:36', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220nyj.htm', 37, 16, 20, '2019-08-21 17:10:37', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220sfo.htm', 37, 16, 20, '2019-08-21 17:10:38', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220sea.htm', 37, 16, 20, '2019-08-21 17:10:39', 'Pass'] ['20130922', 'https://www.pro-football-reference.com/boxscores/201309220pit.htm', 37, 16, 20, '2019-08-21 17:10:39', 'Pass'] ['20130923', 'https://www.pro-football-reference.com/boxscores/201309230den.htm', 37, 16, 20, '2019-08-21 17:10:40', 'Pass'] ['20130926', 'https://www.pro-football-reference.com/boxscores/201309260ram.htm', 36, 15, 20, '2019-08-21 17:10:41', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290buf.htm', 36, 15, 20, '2019-08-21 17:10:42', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290kan.htm', 36, 15, 20, '2019-08-21 17:10:43', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290tam.htm', 36, 15, 20, '2019-08-21 17:10:44', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290htx.htm', 36, 15, 20, '2019-08-21 17:10:45', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290det.htm', 36, 15, 20, '2019-08-21 17:10:46', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290cle.htm', 36, 15, 20, '2019-08-21 17:10:46', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290jax.htm', 36, 15, 20, '2019-08-21 17:10:47', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290min.htm', 36, 15, 20, '2019-08-21 17:10:48', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290oti.htm', 36, 15, 20, '2019-08-21 17:10:49', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290rai.htm', 36, 15, 20, '2019-08-21 17:10:50', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290sdg.htm', 36, 15, 20, '2019-08-21 17:10:51', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290den.htm', 36, 15, 20, '2019-08-21 17:10:51', 'Pass'] ['20130929', 'https://www.pro-football-reference.com/boxscores/201309290atl.htm', 36, 15, 20, '2019-08-21 17:10:52', 'Pass'] ['20130930', 'https://www.pro-football-reference.com/boxscores/201309300nor.htm', 36, 15, 20, '2019-08-21 17:10:53', 'Pass']

MAIN