Skip to content

Instantly share code, notes, and snippets.

View revox's full-sized avatar

Andy Freeman revox

View GitHub Profile
@revox
revox / get_share_counts.py
Created December 9, 2015 12:03
Get the like/share counts for a URL
import requests, json
target_url = "http://www.bbc.co.uk/news/blogs-magazine-monitor-30742506"
apis = ['http://graph.facebook.com/?id=', 'http://cdn.api.twitter.com/1/urls/count.json?url=']
# http://graph.facebook.com/?id= # facebook shares api
# http://cdn.api.twitter.com/1/urls/count.json?url= # twitter shares api
for api in apis:
'''Tweet Streaming API consumer'''
import twitter
import csv
# == OAuth Authentication from your homepage on the twitter developer web site ==
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
@revox
revox / simple_centre_column.html
Created December 1, 2015 18:32
Simple centred column of text of fixed maximum width, a non-responsive plot.ly chart is sized to column width with any padding applied in plot.ly
<!DOCTYPE html>
<html>
<head>
<title>Centred column example</title>
<style>
.container {
max-width:600px;
margin: 0 auto;
font-family: Helvetica;
line-height: 1.4em;
@revox
revox / boundary_scraper.py
Last active November 27, 2015 11:58
Scrape KML name ans boundaries out of mapitmysociety suitable for import to fusion tables. Currently set to scrape wards from the LB of Tower Hamlets
import scraperwiki
import simplejson
import urllib2
import csv
from lxml import etree
# the borough key from mapitmysociety URL for the borough page
TYP = 'LBW'
KEY = '2506'
# typs are:
@revox
revox / tweet_and user_streaming_keyword.py
Last active November 28, 2017 11:45
Extension to last weeks streaming API consumer, now we add some helper functions and broaden our tweet collection to include geographic information if present
'''Tweet Streaming API consumer'''
import twitter
import csv
# == OAuth Authentication ==
consumer_key=""
consumer_secret=""
access_token=""
access_token_secret=""
@revox
revox / simple_json.html
Last active November 26, 2020 15:07
Exercise 1 - Starting code
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
</head>
<body>
<p>
Use the force Luke...(or the console 'View->Developer Tools->JavaScript Console')
@revox
revox / c3_sample.html
Last active November 30, 2018 10:41
Simple C3.js time series example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>C3 demo chart</title>
<meta name="keywords" content="adult obesity, overweight, public health">
<meta name="description" content="Adult obesity has increased in the UK from 1 in 5 to 1 in 4 since 2001">
<!-- Load c3.css -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" type="text/css">
<!-- Load d3.js and c3.js -->
@revox
revox / styler_frag.js
Created November 18, 2015 22:25
Google Maps API styler fragment, paste this into the HTML and JavaScript output from the Fusion Tables Publish function to style the base map
var customMapType = new google.maps.StyledMapType([
{
stylers: [
{hue: '#890000'},
{visibility: 'simplified'},
{gamma: 0.5},
{weight: 0.5}
]
},
{
@revox
revox / get_twitter_profiles.py
Created November 17, 2015 08:35
Reads output from twitter_streaming_api.py and nicely (avoids rate limit) gets the user profiles into a CSV
import twitter
# http://mike.verdone.ca/twitter/ and Russel, MTSW, second edition, 2013
import json, csv, time, sys
consumer_key=""
consumer_secret=""
access_token=""
access_token_secret=""
@revox
revox / twitter_streaming_api.py
Last active November 20, 2017 16:23
Simple twiiter streaming API consumer, writes to CSV file, ignores errors
import twitter, json, sys, csv
# == OAuth Authentication ==
consumer_key=""
consumer_secret=""
access_token=""
access_token_secret=""
auth = twitter.oauth.OAuth(access_token, access_token_secret, consumer_key, consumer_secret)