Skip to content

Instantly share code, notes, and snippets.

@almet
Forked from vleborgne/anxwall.py
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almet/ef7c58cb797ad809317b to your computer and use it in GitHub Desktop.
Save almet/ef7c58cb797ad809317b to your computer and use it in GitHub Desktop.

Comment installer le tweetwall de la cantine ?

C'est parti:

$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
# -*- coding: utf-8 -*-
import re
from twitter import *
from dateutil import parser
import pytz
from termcolor import cprint, colored
import os
import time
import sys
HASHTAG="#WALLNEX"
REFRESH_TIME=30
MAX_TWEETS=10
OAUTH_TOKEN="****"
OAUTH_SECRET="****"
CONSUMER_KEY="****"
CONSUMER_SECRET="****"
####Functions
#Clear console screen
def cls():
os.system(['clear','cls'][os.name == 'nt'])
def header():
cprint(".____/\ ", "magenta")
cprint("| )/ _____ ____ ____ ____ ___ ___ ____ ", "magenta")
cprint("| | \__ \ / \ / \_/ __ \\ \/ // __ \ ", "magenta")
cprint("| |___ / __ \| | \ | \ ___/ > <\ ___/ ", "magenta")
cprint("|_______ (____ /___| /___| /\___ >__/\_ \\___ >", "magenta")
cprint(" \/ \/ \/ \/ \/ \/ \/ ", "magenta")
print("Bienvenue sur le mur de l'annexe")
print("Hashtag " + colored(HASHTAG, "cyan") + " pour apparaitre sur le mur")
def clean():
cls()
header()
def loadTweets(twit):
tweets = twit.search.tweets(q=HASHTAG)
# Max number of tweet to diplay, we cut the array in loop
nbrofTweet = min(MAX_TWEETS, len(tweets['statuses']))
clean()
counter = nbrofTweet
for tweet in tweets['statuses'][:nbrofTweet]:
loadTweet(tweet)
counter -= 1
if counter != 0:
print
sys.stdout.flush()
def loadTweet(tweet):
print(" ")
date_utc = parser.parse(tweet['created_at']).replace(tzinfo=pytz.utc)
local_tz = pytz.timezone("Europe/Paris")
date = date_utc.astimezone(local_tz)
text = tweet['text']
# Strip URLs
text = re.sub(r'https?:\/\/[a-zA-Z0-9\.\/\+\?]+', '', text).strip()
print colored(date.strftime("[%H:%M:%S]"), "cyan"),
print " " + colored("\n".join(text.split("\n")[:3]), "yellow"),
print u" — " + colored(tweet['user']['name'], "red"),
# Authentication based on https://pypi.python.org/pypi/twitter
twit = Twitter(
auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
CONSUMER_KEY, CONSUMER_SECRET))
#TODO Do this with a scheduler
while True:
loadTweets(twit)
time.sleep(REFRESH_TIME)
import sys
from PIL import Image
import numpy as np
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
if len(sys.argv) != 4:
print('Usage: ./asciinator.py image scale factor')
sys.exit()
image = sys.argv[1]
scale = float(sys.argv[2])
factor = float(sys.argv[3])
wcf = 7/4
img = Image.open(image)
S = int(round(img.size[0] * scale * wcf)), int(round(img.size[1] * scale))
img = np.sum(np.asarray(img.resize(S)), axis=2)
img -= img.min()
img = (1.0 - img/img.max()) ** factor * (chars.size - 1)
print("\n".join(("".join(r) for r in chars[img.astype(int)])))
Pillow==2.4.0
argparse==1.2.1
numpy==1.8.1
python-dateutil==2.2
pytz==2014.4
six==1.7.2
termcolor==1.1.0
twitter==1.14.3
wsgiref==0.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment