Skip to content

Instantly share code, notes, and snippets.

@jtg567
jtg567 / deploy
Created January 10, 2016 08:10
Update SQLite DB on Openshift (add to deploy action hook script)
cd $OPENSHIFT_DATA_DIR
echo "Comparing/Updating main_post table in db to sync production to local"
./sqldiff db.sqlite3 $OPENSHIFT_REPO_DIR/data/db.sqlite3 --table main_post > update_db.sql
sqlite3 db.sqlite3 < update_db.sql
@jtg567
jtg567 / scrape.py
Created December 2, 2015 05:08
Use the twitch.tv API with python to see if a particular channel is streaming (python-twitch)
from twitch.api.v3 import streams
# check stream w/twitch api https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamschannel
check = streams.by_channel('<replace channel name>')
# if stream None (not live) then type == dict is False (otherwise True when live)
air_status = type(check['stream']) == dict
@jtg567
jtg567 / scrape.py
Created December 2, 2015 00:14
Scrape token-id from periscope.com with python (lxml and request)
from lxml import html
import requests
#scrape periscope desktop page; meta tag token-id content is empty when not streaming
page = requests.get('https://www.periscope.tv/<replace username>')
tree = html.fromstring(page.content)
air_status = tree.xpath('//*[@id="token-id"]/@content')
@jtg567
jtg567 / scrape.py
Last active December 2, 2015 00:14
Scrape broadcaster_status from mixlr.com with python (lxml and selenium)
from lxml import html
from selenium import webdriver
# scrape from mixlr page after js done (element won't exist otherwise)
driver = webdriver.PhantomJS(executable_path='<replace path>/phantomjs.exe') # another webdriver works fine
driver.get('http://mixlr.com/<replace username>')
tree = html.fromstring(driver.page_source)
air_status = tree.xpath('//*[@id="broadcaster_status"]/span[2]//text()')
driver.quit()