Skip to content

Instantly share code, notes, and snippets.

View johndavidsimmons's full-sized avatar

John Simmons johndavidsimmons

View GitHub Profile
#!/usr/bin/python2.7
# A python example of how to use the update_response method in version 3 of the qualtrics api
# https://api.qualtrics.com/docs/update-response
import requests
import json
url = "https://YOURDATACENTERID.qualtrics.com/API/v3/responses/RESPONSEID"
data = {"surveyId": "SURVEYID", 'embeddedData': {"EDField":"EDValue"}}
headers = {'Content-type': 'application/json', 'X-API-TOKEN' : 'YOURAPITOKEN'}
try:
for _, r in response_data(survey_ids['product']).iteritems():
try:
messageHTML += '''
<p style="margin-bottom: -1em;">Product: <b>{8}</b> Timestamp: <b>{7}</b></p>
<p style="margin-bottom: -1em;">Email: <b>{0}</b></p>
<p style="margin-bottom: -1em;">Overall Rating (1-5): <b>{2}</b></p>
<p style="margin-bottom: -1em;">Likely to Refer (1-5): <b>{4}</b></p>
<p style="margin-bottom: -1em;">Did the website meet your expectations?: <b>{5}</b></p>
<p style="margin-bottom: -1em;">Were you able to accomplish your goal?: <b>{6}</b></p>
/*************** General ***************/
* {
font-family: "myriad-pro",Arial,Helvetica,Garuda,sans-serif;
}
#Wrapper {
max-width: 40em !important;
margin: 0 auto !important;
}
@johndavidsimmons
johndavidsimmons / m3u.py
Created August 16, 2016 17:16 — forked from jonlabelle/m3u.py
Generate an mp3 playlist file (.m3u), sorted by album track number.
#!/usr/bin/env python
import os
import sys
import glob
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3
#
# MP3 playlist generator
@johndavidsimmons
johndavidsimmons / browser.py
Created January 27, 2017 15:00
Setting up the Selenium Chromedriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import os
def chromeDriver():
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
@johndavidsimmons
johndavidsimmons / .env
Created January 30, 2017 17:49
Example .env file
CHROME_DRIVER_PATH=/Users/{{name}}/{{example}}/venv/selenium/webdriver/chrome/chromedriver
@johndavidsimmons
johndavidsimmons / findAllAnchors.py
Created January 30, 2017 21:39
Return a set of the relative anchors on the given page
def findAllAnchors(url):
# Use requests to get page source without using driver
r = requests.get(url)
# Turn the page source into soup for parsing
soup = bs4(r.text, "html5lib")
# Return a Set of relative anchors tags from a given
return set([anchor for anchor in soup.find_all('a', href=True) if anchor['href'].startswith('/') and not anchor['href'].endswith(('.com', '.org', '.net'))])
def visitPage(url, relativeUrl):
global driver
global HTML_string
# Visit the page
driver.get(url+relativeUrl)
# Turn on staging and debug (Optional)
# driver.execute_script(stagingScript)
# driver.execute_script(debugScript)
@johndavidsimmons
johndavidsimmons / pyaa.py
Created February 1, 2017 16:09
The main function for checking Adobe Analytics
def main():
global target_url
global HTML_string
global driver
relative_anchors = findAllAnchors(target_url)
# Iterate the relative anchors and collect data
for anchor in relative_anchors:
anchorHref = str(anchor['href'])
$.ajax({
async: false,
type: 'GET',
url : 'https://survey.qualtrics.com//WRAPI/ControlPanel/api.php?API_SELECT=ControlPanel&Version=2.5&Request=getLegacyResponseData&User=USERNAME&Token=APITOKEN&Format=JSON&SurveyID=SURVEYID&StartDate=2017-02-02%2000%3A00%3A00&LocationData=1',
success: function(data) {
console.log(data);
}
});