for i in range(delta+1):
    dates.append(str(date11+td(days=i)))
print dates


# Create the blank dateframe to store data
df=pd.DataFrame(np.zeros(0,dtype=[('date','a30'),('theme','a30'),('category','a20'),('URL','a50'),
                                  ('pageviews','I4'),('sessions','I4'),('clicks','I4'),('bouncerate','f8')]))

# Read the PCMag URL tracking sheet from our G-Drive
GAURL=pd.read_csv("G:/Commerce/Chen/PCMagGAURL.csv")


# User Google Analytics function we created to get the data
for index,row in GAURL.iterrows():
    URLtracking=row['URL']
    theme=row['Theme_MySQL']
    Category=row['Category']
    tryR0=gf.URLpageviews(service,profile,URLtracking,Daterequest.daterequest,Daterequest.daterequest)
    tryR1=gf.URLsessions(service,profile,URLtracking,Daterequest.daterequest,Daterequest.daterequest)
    tryR2=gf.URLbouncerate(service,profile,URLtracking,Daterequest.daterequest,Daterequest.daterequest)
    tryR3=gc.gaclicks(service,profile,URLtracking,Daterequest.daterequest,Daterequest.daterequest)
    for i in range(delta+1):
        df=df.append({'date':dates[i],'theme':theme,'category':Category,'URL':URLtracking,'pageviews':tryR0[i][1],
                      'sessions':tryR1[i][1],'clicks':tryR3[i],'bouncerate':tryR2[i][1]},ignore_index=True)
    time.sleep(0.5)
print df

# Read out to a csv file and read the csv file into a dataframe
df.to_csv("C:/Users/cgao/Desktop/Ziff/GoogleAnalytics/GA_PCMag_page"+Daterequest.daterequest+"to"+
          Daterequest.daterequest+"roundupgooglesheetrenew.csv",index=True)
for i in range(delta+1):
    dates.append(str(date11+td(days=i)))
print dates


# Create the blank dateframe to store data
df=pd.DataFrame(np.zeros(0,dtype=[('date','a30'),('theme','a30'),('category','a20'),('URL','a50'),
                                  ('pageviews','I4'),('sessions','I4'),('clicks','I4'),('bouncerate','f8')]))

# Read the PCMag URL tracking sheet from our G-Drive
GAURL=pd.read_csv("G:/Commerce/Chen/PCMagGAURL.csv")


# User Google Analytics function we created to get the data
for index,row in GAURL.iterrows():
    URLtracking=row['URL']
    theme=row['Theme_MySQL']
    Category=row['Category']
    tryR0=gf.URLpageviews(service,profile,URLtracking,yesterday,yesterday)
    tryR1=gf.URLsessions(service,profile,URLtracking,yesterday,yesterday)
    tryR2=gf.URLbouncerate(service,profile,URLtracking,yesterday,yesterday)
    tryR3=gc.gaclicks(service,profile,URLtracking,yesterday,yesterday)
    for i in range(delta+1):
        df=df.append({'date':dates[i],'theme':theme,'category':Category,'URL':URLtracking,'pageviews':tryR0[i][1],
                      'sessions':tryR1[i][1],'clicks':tryR3[i],'bouncerate':tryR2[i][1]},ignore_index=True)
    time.sleep(0.5)
print df

# Read out to a csv file and read the csv file into a dataframe
df.to_csv("C:/Users/cgao/Desktop/Ziff/GoogleAnalytics/GA_PCMag_page"+yesterday+"to"+
          yesterday+"roundupgooglesheetrenew.csv",index=True)