A really crummy hack to present factoids etc on the LED matrix


In [36]:
import random

import sys
from twython import Twython, TwythonError
import time

# various keys for twitter etc
from private import *

In [37]:
# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

seen = set()
twitter_refresh = 60
twitter_last = 0

def get_tweets():
    global twitter_last
    tweets = []
    if time.time() - twitter_last < twitter_refresh:
        # do not check yet
        return tweets
    twitter_last = time.time()
    # hashtags
    for hashtag in ['sfn15', 'pymvpa', 'datalad', 'neurodebian']:
        try:
            search_results = twitter.search(q='#' + hashtag, count=10)
            tweets.extend(search_results['statuses'])
        except TwythonError as e:
            print e

    # our timeline
    tweets.extend(twitter.get_user_timeline())

    had_new = False
    out = []
    for tweet in tweets:
        id_ = tweet['id']
        if id_ in seen:
            continue
        seen.add(id_)
        had_new = True
        out.append({
            'text': tweet['text'],
            'source': '@'+tweet['user']['screen_name'].encode('utf-8'),
            'tweet': tweet['id']})
        #print "%s\n@%s https://twitter.com/statuses/%s\n" % (tweet['text'],
        #                        tweet['user']['screen_name'].encode('utf-8'),
        #                        #tweet.get('urls', {}).get('url', ''),
        #                        tweet['id']
        #                        )
        #sys.stdout.flush()

    return out
    #if had_new:
    #    print "sleeping"
    #    sys.stdout.flush()
    #time.sleep(60)

In [38]:
import yaml

def render_entry(d):
    # first line will always be just a text
    l1 = d['text']
    # compose 2nd line if present
    l2 = ''
    if len(d)>1:
        l = [d.get('source', '')]
        l.append(d.get('url')) # TODO: shorten
        if 'tweet' in d:
            l.append('https://twitter.com/ChrisFiloG/status/%s' % d['tweet'])
        if 'doi' in d:
            l.append('http://dx.doi.org/%s' % d['doi'])

        l2 = ' '.join(filter(bool, l))
    # indent 2nd line so it right aligned
    if l2:
        l2 = ' '*(max(0, len(l1) - len(l2))) + l2
    return l1, l2

stream = open("factoids.yaml", "r")
docs = yaml.load_all(stream)
factoids = []
for doc_ in docs:
  for doc in doc_:  
    factoids.append(doc)

In [ ]:
# so we have factoids and also can ask for new tweets from time to time
while True:
    pool = get_tweets()
    if not pool:
        # get random factoid
        pool = [random.choice(factoids)]
    for doc in pool:
        print "\n".join(filter(bool, render_entry(doc)))
        print "\n",
        time.sleep(1) # as we had presented it for 1 sec


I will be bumping this tweet up a lot until #sfn15 #sorrynotsorry #listforthepeople https://t.co/Qe9Bx5X8P9
                                         @neurofim https://twitter.com/ChrisFiloG/status/653217110177509378

RT @edizquierdo: I'll be covering some of the work at #SfN15 for #PLOS. Expect a focus on computational neuroscience, behavior and cognitio…
                                                                         @PLOSNeuro https://twitter.com/ChrisFiloG/status/653202915658727424

Dear neuro-tweeps: should poster text blocks be justified or left-aligned? #SfN15 #NoTextIsBetter #IKnowButICantHelpMyself
                                                 @pierre_vanmedge https://twitter.com/ChrisFiloG/status/653202496194785280

RT @yoavsibony: #HEKA symposium #SfN15
Patchmaster: Introduction
PatchServer: Automatic Patch Clamp System 
Sunday, Oct 18th, 6:30pm http:/…
                                                                      @Channelomics https://twitter.com/ChrisFiloG/status/653200933363564544

RT @neurofim: https://t.co/23bIbXlWtp Whilst this list is long and distinguished (unlike my career), it needs YOU! #sfn15
                                                      @devduthie https://twitter.com/ChrisFiloG/status/653170829149077504

@AV_SP will do! (and follow @PLOSNeuro and our list https://t.co/j99rLetwCc for live #SfN15 coverage :)
                              @pierre_vanmedge https://twitter.com/ChrisFiloG/status/653161246070546432

@pierre_vanmedge &gt;.. attending #SfN15? Unfortunately, no. If you're ever in Sydney, drop me a line!
                                       @AV_SP https://twitter.com/ChrisFiloG/status/653160780301385728

#sfn15 or #sfn2015? N(tweets) since 1st Oct marginally tips #sfn2015 but I'm with @doc_becca: need those 2 characters. Both would be silly!
                                                                  @Science2Inspire https://twitter.com/ChrisFiloG/status/653160720343912448

RT @TheColeLab: The Cole Lab has 4 poster presentations at #SfN15, covering brain networks, dynamics, and cognitive control http://t.co/sZO…
                                                                          @eglerean https://twitter.com/ChrisFiloG/status/653142213547958272

@AV_SP hi, will you be attending #SfN15? Would enjoy a chat with you
@pierre_vanmedge https://twitter.com/ChrisFiloG/status/653139784349708288

RT @NeuroDebian: de-v #neurodebian mirror (http://t.co/KpQTFHREFx) was decomissioned -- please choose another mirror if it was your primary.
                                                                            @esc___ https://twitter.com/ChrisFiloG/status/652916045381042178

de-v #neurodebian mirror (http://t.co/KpQTFHREFx) was decomissioned -- please choose another mirror if it was your primary.
                                                      @NeuroDebian https://twitter.com/ChrisFiloG/status/652915316712865792

RT @NeuroDebian: FSL 5.0.9 rolling into #NeuroDebian. 32bit users, please be patient. Eddy users watch out for fsl-5.0-eddy-nonfree!
                                                              @AmirHusseinA https://twitter.com/ChrisFiloG/status/652473145409056768

FSL 5.0.9 rolling into #NeuroDebian. 32bit users, please be patient. Eddy users watch out for fsl-5.0-eddy-nonfree!
                                              @NeuroDebian https://twitter.com/ChrisFiloG/status/652467162070818817

RT @NeuroDebian: New-package-frenzy: dcm2niix, heudiconv, mridefacer, and dcmstack now available from #NeuroDebian
                                                @wandedob https://twitter.com/ChrisFiloG/status/652347896285818881

New-package-frenzy: dcm2niix, heudiconv, mridefacer, and dcmstack now available from #NeuroDebian
                            @NeuroDebian https://twitter.com/ChrisFiloG/status/652345194310946816

Just testing -- posting
@yarikoptictest https://twitter.com/ChrisFiloG/status/653023997869846529

[In bioinformatics] The citation benefit was greatest for data published in 2004 and 2005, at about 30%
    Data reuse and the open data citation advantage, Piwowar&Vision http://dx.doi.org/10.7717/peerj.175

Brainhack Americas will be held in 10 cities across 5 time zones on Oct 23-25. Everyone is welcome to join!
    https://docs.google.com/spreadsheets/d/1JpkqwuvVLtLgj1rxlvaIC2dxD2qGMXmqHHJfejKWGA0/edit#gid=1157977888

Just 38% of 394 data sharing requests fulfilled [for four APA journals in 2012]
Are We Wasting a Good Crisis? ..., Vanpaemel et al, 2015 http://dx.doi.org/10.1525/collabra.13

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

Just 38% of 394 data sharing requests fulfilled [for four APA journals in 2012]
Are We Wasting a Good Crisis? ..., Vanpaemel et al, 2015 http://dx.doi.org/10.1525/collabra.13

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

There are 9336 statistical maps, masks, atlases and parcellation in http://NeuroVault.org
                     @ChrisFiloG https://twitter.com/ChrisFiloG/status/644210801964781568

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

There are 9336 statistical maps, masks, atlases and parcellation in http://NeuroVault.org
                     @ChrisFiloG https://twitter.com/ChrisFiloG/status/644210801964781568

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

[In bioinformatics] The citation benefit was greatest for data published in 2004 and 2005, at about 30%
    Data reuse and the open data citation advantage, Piwowar&Vision http://dx.doi.org/10.7717/peerj.175

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

NeuroSynth (http://neurosynth.org) dataset contains 413429 activations reported in 11406 studies and a meta-analyses of 3107 terms

Just 38% of 394 data sharing requests fulfilled [for four APA journals in 2012]
Are We Wasting a Good Crisis? ..., Vanpaemel et al, 2015 http://dx.doi.org/10.1525/collabra.13

Haxby 2001 Faces and Objects in Ventral Temporal Cortex (fMRI) dataset was reused over in 40 publications

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

NeuroSynth (http://neurosynth.org) dataset contains 413429 activations reported in 11406 studies and a meta-analyses of 3107 terms

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

NeuroSynth (http://neurosynth.org) dataset contains 413429 activations reported in 11406 studies and a meta-analyses of 3107 terms

“68% (95%-CI [64, 72]) of [neuroscientists] reported to be using [GNU/Linux] … 52% for Windows and 26% for Mac OS X”
                     Neuroscience runs on GNU/Linux, Hanke&Halchenko 2001 http://dx.doi.org/10.3389/fninf.2011.00008

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

Just 38% of 394 data sharing requests fulfilled [for four APA journals in 2012]
Are We Wasting a Good Crisis? ..., Vanpaemel et al, 2015 http://dx.doi.org/10.1525/collabra.13

[In bioinformatics] The citation benefit was greatest for data published in 2004 and 2005, at about 30%
    Data reuse and the open data citation advantage, Piwowar&Vision http://dx.doi.org/10.7717/peerj.175

Haxby 2001 Faces and Objects in Ventral Temporal Cortex (fMRI) dataset was reused over in 40 publications

Just 38% of 394 data sharing requests fulfilled [for four APA journals in 2012]
Are We Wasting a Good Crisis? ..., Vanpaemel et al, 2015 http://dx.doi.org/10.1525/collabra.13

Brainhack Americas will be held in 10 cities across 5 time zones on Oct 23-25. Everyone is welcome to join!
    https://docs.google.com/spreadsheets/d/1JpkqwuvVLtLgj1rxlvaIC2dxD2qGMXmqHHJfejKWGA0/edit#gid=1157977888

[In bioinformatics] The citation benefit was greatest for data published in 2004 and 2005, at about 30%
    Data reuse and the open data citation advantage, Piwowar&Vision http://dx.doi.org/10.7717/peerj.175

Haxby 2001 Faces and Objects in Ventral Temporal Cortex (fMRI) dataset was reused over in 40 publications

“The human brain produces in 30 seconds as much data as the Hubble Space Telescope has produced in its lifetime.”
                                                  Konrad Kording of Northwestern University in Chicago, Illinois.

There are 9336 statistical maps, masks, atlases and parcellation in http://NeuroVault.org
                     @ChrisFiloG https://twitter.com/ChrisFiloG/status/644210801964781568

There are 9336 statistical maps, masks, atlases and parcellation in http://NeuroVault.org
                     @ChrisFiloG https://twitter.com/ChrisFiloG/status/644210801964781568

In [ ]: