This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Essentials ### | |
import pandas as pd # for working with the data | |
import requests # calling on various APIs used in this process | |
import urllib # for developing URLs for REST API calls | |
# Time Manipulation # | |
from calendar import monthrange # for developing timeframes on a monthly basis | |
import datetime # for compiling dates so we never have to load in time variables every month | |
import time # for basic time manipulaltion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### SERP Presence ### | |
### Load SEMRush Credentials and URLs for API call. | |
api_key = 'api key goes here' | |
service_url = 'https://api.semrush.com' | |
client_url = 'https://www.clientsite.com/' | |
### Various time manipulations for each part of the report ### | |
today = datetime.date.today() | |
first = today.replace(day=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service_url = 'https://api.semrush.com/analytics/v1/' | |
def backlink_url_build(): | |
params = { | |
"?type": "backlinks", | |
'key': api_key, | |
'target': "clientsite.com", | |
'target_type': 'root_domain', | |
'display_limit': '30000', | |
'display_sort': 'first_seen_desc' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Record All Data ### | |
writer = pd.ExcelWriter('kpi_report_%s.xlsx' % (date_main), engine='xlsxwriter') | |
# Write each dataframe to a different worksheet. | |
final_search_presence.to_excel(writer, sheet_name='SERP Presence') | |
serp_results.to_excel(writer, sheet_name='SERP Engagement') | |
new_bl.to_excel(writer, sheet_name="{} Backlinks".format(len(new_bl.first_seen))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### SERP Engagement ### | |
def serp_engagement(): | |
account = searchconsole.authenticate(client_config='C:/Users/My.Computer/search_console_credentials.json', | |
credentials='C:/Users/My.Computer/search_console_serialized_creds.json') | |
webproperty = account['https://www.clientsite.com/'] | |
frames = [] | |
report = webproperty.query.range(search_console_date, days=day).dimension('query').get() | |
sc_data = [] | |
for kw_row in report.rows: | |
keyword = kw_row[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Essentials # | |
import pandas as pd | |
import urllib | |
import requests | |
import time | |
import sys | |
# UI # | |
import easygui | |
from easygui import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for Plotly API Credentials, create a json file with credentials | |
import json | |
with open('path_to_credentials.json') as f: | |
creds = json.load(f) | |
# Essentials | |
import math | |
x = float('nan') | |
import pandas as pd | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Essentials | |
import pandas as pd | |
import numpy as np | |
from time import sleep | |
from random import randint | |
# Trends API | |
from pytrends.request import TrendReq | |
# Optional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service_url = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed/" | |
def speed_test_url(url, device): | |
params = { | |
"?url": url, | |
'strategy': device, | |
'key': key, | |
} | |
data = urllib.parse.urlencode(params, doseq=True) | |
main_call = urllib.parse.urljoin(service_url, data) | |
main_call = main_call.replace(r'%3F', r'?') |
OlderNewer