from googleapiclient.discovery import build
import pandas as pd
from bs4 import BeautifulSoup
import requests
import numpy as np

my_api_key = "AIzaSyC-djDYtVMjEJSubc8oaE-W-EEUrHJD0g0" #NOTE: I USED ALL MY CALLS LOL SO GET A NEW KEY AND REGISTER SHIT
my_cse_id = "013234493367067861201:e_sqh9dvrhy"

def google_search(search_term, api_key, cse_id, **kwargs):
    service = build("customsearch", "v1", developerKey=api_key)
    res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
    return res['items']

PLAYERS = ["Lebron James", "Russell Westbrook", "Stephen Curry", "Paul George", "Kevin Durant"]
for player in PLAYERS:
	results = google_search(player, my_api_key, my_cse_id, num=1)
	print results[0]["formattedUrl"]
	stats = pd.read_html("https://"+results[0]["formattedUrl"])
	df = pd.DataFrame(stats[0])

	for index, row in df.iterrows():
		if index == 0:
			rookie_stats = row
			break
	rookie_stats = rookie_stats[:25]
	print (np.asarray(rookie_stats))[5:]
	print len((np.asarray(rookie_stats))[5:])
@@ -123,16 +123,129 @@
  as np%0A%0A
+%0Aplayer_list = open(%22players.txt%22, %22r%22)%0Aall_players = %5B%5D%0Afor player in player_list:%0A%09all_players.append(player)%0A%0A
 my_api_k
@@ -632,128 +632,151 @@
 s'%5D%0A
-%0APLAYERS = %5B%22Lebron James%22, %22Russell Westbrook%22, %22Stephen Curry%22, %22Paul George%22, %22Kevin Durant%22%5D%0Afor player in PLAYERS
+    %0A# all_players = %5B%22lil dicky%22, %22Lebron James%22, %22Stephen Curry%22, %22Chris Paul%22%5D%0Aplayer_feature_tensor = %5B%5D%0Afor player in all_players:%0A%09try
 :%0A
+%09
 %09res
@@ -834,16 +834,17 @@
  num=1)%0A
+%09
 %09print r
@@ -869,16 +869,17 @@
 edUrl%22%5D%0A
+%09
 %09stats =
@@ -931,16 +931,17 @@
 dUrl%22%5D)%0A
+%09
 %09df = pd
@@ -962,16 +962,17 @@
 ts%5B0%5D)%0A%0A
+%09
 %09for ind
@@ -999,16 +999,17 @@
 ws():%0A%09%09
+%09
 if index
@@ -1015,16 +1015,17 @@
 x == 0:%0A
+%09
 %09%09%09rooki
@@ -1045,14 +1045,16 @@
 %0A%09%09%09
+%09
 break%0A
+%09
 %09roo
@@ -1083,16 +1083,17 @@
 ts%5B:25%5D%0A
+%09
 %09print (
@@ -1122,16 +1122,17 @@
 s))%5B5:%5D%0A
+%09
 %09print l
@@ -1165,8 +1165,192 @@
 s))%5B5:%5D)
+%0A%09%09player_feature_tensor.append((np.asarray(rookie_stats))%5B5:%5D)%0A%09except (RuntimeError, TypeError, NameError, KeyError):%0A%09%09pass%0A%0Aprint np.asarray(player_feature_tensor, dtype = float)%0A%0A

set up numpy tensor and try catch