Skip to content

Instantly share code, notes, and snippets.

View revox's full-sized avatar

Andy Freeman revox

View GitHub Profile
@revox
revox / Summary and Detail Example
Created October 25, 2013 16:33
Using <SUMMARY> and <DETAIL> in WordPress posts
<style>
summary::-webkit-details-marker {
color: #00ACF3;
margin-right: 2px;
}
summary:focus {
outline-style: none;
}
article > details > summary {
font-size: 18px;
@revox
revox / tweepy_streamer.py
Created December 10, 2013 08:38
Shows current tweet rate via the twitter streaming API using tweepy. Also some fragments for spotting retweets, conversations and inspecting tweet objects.
#
#
# based on https://github.com/tweepy/tweepy/blob/master/examples/streaming.py
import tweepy # to get your tweepy version go python -c "import tweepy; print(tweepy.__version__)"
import time
import json
import datetime
@revox
revox / scrape_ons_release_start.py
Created January 13, 2014 23:05
Starting code for ONS schedule scrape
'''A script to scrape the ONS release schedule'''
import urllib
import bs4
page = 0
URL = "http://www.statistics.gov.uk/hub/release-calendar/index.html?newquery=*&newoffset=" + str(page) + "&theme=%22%22&source-agency=%22%22&uday=0&umonth=0&uyear=0&lday=-29&lmonth=0&lyear=0&coverage=%22%22&designation=&geographic-breakdown=%22%22&title=%22%22&pagetype=calendar-entry&sortBy=releaseDate&sortDirection=EITHER"
# open webpage
webpage = urllib.urlopen(URL).read()
@revox
revox / graph_one.html
Last active November 1, 2018 10:06
Google Visualisation API Example - Tweet time series with data from Google sheet
<!DOCTYPE html>
<html>
<head>
<title>Twitter volume</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the core charts package.
google.load('visualization', '1.0', {
@revox
revox / lewisham_schools_with_nurseries.sparql
Created February 3, 2014 20:54
SPARQL query to get schools with nurseries in a ONS code (run at http://openuplabs.tso.co.uk/sparql/gov-education)
PREFIX sch-ont: <http://education.data.gov.uk/def/school/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name ?ptr ?address1 ?address2 ?postcode ?town WHERE {
?school a sch-ont:School;
sch-ont:establishmentName ?name;
sch-ont:nurseryProvision "true"^^xsd:boolean;
sch-ont:districtAdministrative <http://statistics.data.gov.uk/id/local-authority-district/00AZ>.
OPTIONAL {
?school sch-ont:address ?address.
@revox
revox / tweepytest.py
Last active May 28, 2021 14:12
Use tweepy to write some tweet info into a CSV file
import time
import tweepy
import csv
# == OAuth Authentication ==
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key="your key"
consumer_secret="your secret"
@revox
revox / youtube_scraper.py
Last active May 30, 2021 06:24
Basic scrape and write to CSV example using BS4
# basic scrape and write demonstration used in Goldsmiths digital sandbox 2014
import urllib # fetches raw web pages for us
import bs4 # turns raw web pages into object hierarchy and provides selectors (like CSS and Xpath does)
import csv # simplifies the process of writing data to Comma Separated Values in a file
# a list of URLs on YouTube that we want to scrape data from
pagesToScrape = ['http://www.youtube.com/watch?v=9hIQjrMHTv4'
,'https://www.youtube.com/watch?v=Uk8x3V-sUgU']
# open a file in append mode to write into in the same directory where we ran this script from
import twitter
import json
# == OAuth Authentication ==
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key=""
consumer_secret=""
# After the step above, you will be redirected to your app's page.
# Finding topics of interest by using the filtering capablities it offers.
import twitter
import json
import sys
# == OAuth Authentication ==
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "Keys and tokens")
# PUT YOUR KEYS AND SECRETS IN HERE, IT WONT WORK WITHOUT YOUR KEYS FROM TWITTER !!!!!
consumer_key=""
@revox
revox / streaming_twitter_user.py
Last active August 29, 2015 14:10
Follow a user or list of users tweets and write them to CSV
# Finding topics of interest by using the filtering capablities it offers.
import twitter, json, sys, csv
# == OAuth Authentication ==
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key=""
consumer_secret=""
# After the step above, you will be redirected to your app's page.