示例#1
0
def collect(file_types): 
	"""
	Requires: a sequence of file types (in strings) whose numbers of downloads 
	we want to count.

	Effects: Grabs the download numbers of specified file types from the mysql database. 
	Returns a sequence of integers. 
	"""
	DATABASE = login.getCredentials('sql-database', 'database')
	HOST = login.getCredentials('sql-database', 'host')
	USERNAME = login.getCredentials('sql-database', 'username')
	PASSWORD = login.getCredentials('sql-database', 'password')
	counts = []
	months = []
	conn = mysql.connector.connect(database = DATABASE, host = HOST, user = USERNAME, password = PASSWORD)
	cur = conn.cursor();

	curmonth_query = "SELECT CURDATE()"
	cur.execute(curmonth_query)
	curmonth = str(cur.fetchone()[0])[:7]
	months.insert(0, curmonth)

	# Get the range of months that we want data for
	month = curmonth
	for i in range(12): 
		if month[-2:] != "01" and int(month[-2:]) < 10:
			month = month[:-1] + str(int(month[-2:]) - 1) 
		elif month[-2:] == "01": 
			month = str(int(month[:4]) - 1) + "-12"
		elif int(month[-2:]) == 10: 
			month = month[:-2] + "0" + str(int(month[-2:]) - 1)
		else: 
			month = month[:-2] + str(int(month[-2:]) - 1)
		months.insert(0, month)
	# print(months)

	# Execute queries of counting specific file types' downloads
	query = "SELECT COUNT(*) FROM `pis_downloads` WHERE SUBSTRING(`file`, -3, 3) = '%s' AND SUBSTRING(`date`, 1, 7) = SUBSTRING('%s', 1, 7)"
	for month in months: 
		counts_month = []
		for file_type in file_types: 
			cur.execute(query % (file_type, month))
			counts_month.append(cur.fetchone()[0])
		counts.append(counts_month)

	conn.close()

	return counts
示例#2
0
def get_session_user(pageName):
    viewId = login.getCredentials('google-analytics', pageName)
    dateRanges = date.dateRange()
    sessions = []
    users = []

    for item in dateRanges:
        data = get_data(viewId, item)
        sessions.append(data[0])
        users.append(data[1])
    return sessions, users


# print (get_data('133181834', {'startDate': '2018-07-01', 'endDate': '2018-07-31'}))
# print (get_data_set('katalyst-education'))
# print (get_report('channel==MINE','2018-07-01',endDate='2018-07-01'))
# print (get_session_user('katalyst-education'))
# print (date.dateRange()[-2:])
# print (get_report('118319780'))
# print (get_data('177495530'))
# print (get_user('katalyst-education'))
示例#3
0
def login():
    username = login_helper.getCredentials('jira', 'username')
    password = login_helper.getCredentials("jira", "password")
    return (username, password)
# import requests
# import json
# import facebook
import login_helper as login
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# driver = webdriver.PhantomJS('/Users/zhuxinyang/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs')

USERNAME = login.getCredentials('facebook', 'ke-username')
PASSWORD = login.getCredentials('facebook', 'ke-password')
CHROME_ADDR = '/Users/zhuxinyang/Downloads/chromedriver'


def get_pis():
    """
	GET function for Pi-Stacja data: number of followers and likes. 
	Return an array of two integers. 
	"""
    # Use the selenium webdriver API
    driver = webdriver.Chrome(CHROME_ADDR)

    # Get number of followers
    driver.get(
        'https://www.facebook.com/PistacjaMatematyka/insights/?section=navFollowers'
    )
    # Login
    email_element = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.ID, "email")))
示例#5
0
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import login_helper as login

service = login.gspread_auth()
spreadsheet_id = login.getCredentials("google-sheet", "id")
spreadsheet = service.spreadsheets().values()


def add_new_row(dataArray, sheetName, Range):
    row_range = sheetName + "!" + Range
    input_option = 'RAW'
    insert_option = 'INSERT_ROWS'
    data_value = [dataArray]
    data_body = {'values': data_value}
    request = spreadsheet.append(spreadsheetId=spreadsheet_id,
                                 range=Range,
                                 valueInputOption=input_option,
                                 insertDataOption=insert_option,
                                 body=data_body)
    return request


"""
Code for Google spreadsheet API
"""

scope = [
    'https://spreadsheets.google.com/feeds',
    'https://www.googleapis.com/auth/drive'
]
import requests
import json
import login_helper as login

####run pip install requests before running this code!
auth_data = open('auth-info.json')
auth_json = json.load(auth_data)
CHANNEL_ID = login.getCredentials('youtube',
                                  'channel-id')  #hard-coded instance rn
AUTH_KEY = login.getCredentials('youtube', 'auth-key')  #hard-coded instance

YOUTUBE_RAW_DATA = requests.get(
    "https://www.googleapis.com/youtube/v3/channels?" + "part=statistics&id=" +
    CHANNEL_ID + "&key=" + AUTH_KEY)


def request_stats():
    return requests.get("https://www.googleapis.com/youtube/v3/channels?" +
                        "part=statistics&id=" + CHANNEL_ID + "&key=" +
                        AUTH_KEY)


def get_statistics(raw_data, param):
    if raw_data.status_code != 200:
        print('Error getting data, check key or id!')
        return
    else:
        data = raw_data.json()['items'][0]['statistics'][param]
        return data

import requests
import json
import facebook
import login_helper as login
AUTH_TOKEN = login.getCredentials('facebook','auth-token')
PAGE_ID = login.getCredentials('facebook','page-id')
graph = facebook.GraphAPI(access_token = AUTH_TOKEN)
page = graph.get_object(id=PAGE_ID,fields='fan_count')

def getLikes():
	return graph.get_object(id=PAGE_ID,fields='fan_count').get('fan_count')

def printLikes():
	print ("Facebook Likes = " + str(getLikes()) + "Likes ")

print (getLikes())