Skip to content

Instantly share code, notes, and snippets.

@rahulbot
rahulbot / .block
Last active March 17, 2017 15:18 — forked from kerryrodden/.block
Sequences sunburst
license: apache-2.0
@rahulbot
rahulbot / mc_recent_tags.py
Last active February 22, 2018 00:52
Querying Media Cloud for the top recent tags on stories
MC_APY_KEY = "MY_KEY"
mc = mediacloud.api.AdminMediaCloud(MY_KEY)
# tag sets that hold tags on stories
NYT_LABELS_TAG_SET = 1963 # one tag per theme in a story (Jasmin's transfer-learning model)
GEO_TAG_SET = 1011 # one tag per country/state stories are about (disambiguated)
CLIFF_ORGS_TAG_SET = 2388 # one tag for each org mentioned in stories
CLIFF_PEOPLE_TAG_SET = 2389 # one tag for each perosn mentioned in stories
US_PEW_TOP_MEDIA_COLLECTION_ID = 9139487
@rahulbot
rahulbot / mc_basic_queries.py
Last active February 22, 2018 01:03
Using MediaCloud to query for coverage in media or collections
keywords = "inequality"
sources = [28, # Miami Helard
39] # South Florida Sun Sentinel
collections = [38379430] # Florida state & local
mc = mediacloud.api.AdminMediaCloud(API_KEY)
# how many sentences have used this word in the last 3 months?
print(mc.sentenceCount(keywords, ["media_id: ({})".format(" ".join(map(str, sources))),
'publish_date:NOW to NOW-3MONTH']))
# how many stories have used this word in the last 3 months?
print(mc.storyCount(keywords, ["media_id: ({})".format(" ".join(map(str, sources))),
@rahulbot
rahulbot / random.py
Created March 12, 2018 18:14
mc_random_sources_from_collecitons
def media_with_tag(tags_id, cached=False):
more_media = True
all_media = []
max_media_id = 0
while more_media:
media = mc.mediaList(tags_id=tags_id, last_media_id=max_media_id, rows=100)
all_media = all_media + media
if len(media) > 0:
max_media_id = media[len(media) - 1]['media_id']
more_media = len(media) != 0
@rahulbot
rahulbot / mc_story_list_paging.py
Last active October 2, 2018 13:52
Querying Media Cloud for a list of all the matching stories
all_stories = []
florida_collection_id = 38379430
stories_per_page = 50
last_id = 0
more_stories = True
while more_stories:
story_page = mc.storyList('(puppy OR puppies) AND tags_id_media:{}'.format(florida_collection_id),
'publish_date:[NOW-30DAY TO NOW]', last_processed_stories_id=last_id,
rows=stories_per_page)
if len(story_page ) is 0:
@rahulbot
rahulbot / itunes_to_rss.rb
Created February 19, 2020 09:33 — forked from crm114/itunes_to_rss.rb
Get RSS feeds for iTunes Podcast links
# gem install httparty
# gem install nokogiri
# gem install feedjira
require 'httparty'
require 'nokogiri'
require 'feedjira'
module ItunesToRSS
def self.extract(url)
headers = { 'User-Agent' => 'iTunes/10.1 (Windows; U; Microsoft Windows XP Home Edition Service Pack 2 (Build 2600)) DPI/96' }
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 800,
"height": 300,
"style": "cell",
"data": [
{"name": "selector304_store"},
{
@rahulbot
rahulbot / center-left.csv
Created February 12, 2021 00:35
data for viz testing
date count total percentage word
2019-12-30 3 49 0.0612 bigoted
2020-01-06 3 84 0.0357 bigoted
2020-01-13 2 83 0.0241 bigoted
2020-01-20 1 137 0.0073 bigoted
2020-01-27 3 236 0.0127 bigoted
2020-02-03 4 268 0.0149 bigoted
2020-02-10 5 203 0.0246 bigoted
2020-02-17 3 286 0.0105 bigoted
2020-02-24 3 220 0.0136 bigoted
{
"coord": {
"lon": -71.0589,
"lat": 42.3601
},
"weather": [
{
"id": 701,
"main": "Mist",
"description": "mist",
@rahulbot
rahulbot / data-array-example.ino
Created February 14, 2023 20:00
Arduino data example
#include <Servo.h> // use a set of functions to control the servo
int potPosition; // keep track of the potentiometer's last value
int dataIndex; // keep track of the index of the data item we're showing
int servoPosition; // keep track of where the servo is
Servo myservo; // make a servo helper object
int SERVO_PIN = 3; // the phyiscal pin we'll attach the servo to
int data[] = {1,10,10,10,1,2,4,5,10,10,0}; // an array of made up data