Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import json
- import codecs
- import Image
- from ImageOps import invert
- from math import sqrt, pi, sin
- from sys import argv
- import calendar
- import time
- latrange = [45, 46]
- lonrange = [-123.5, -122]
- latgrain = 1/500.0/sqrt(2) # heehee
- longrain = 1/500.0
- width = int(round((lonrange[1]-lonrange[0]) * 1/longrain))
- height = int(round((latrange[1]-latrange[0]) * 1/latgrain))
- i = Image.new('RGB', (width, height))
- pixels = i.load()
- colorincrement = 100
- def kz1(v):
- v = v * pi
- r = sin(v)
- g = sin(pi * 2.0/3.0 + v)
- b = sin(pi * 4.0/3.0 + v)
- return (int(r*r*255), int(g*g*255), int(b*b*255))
- input = codecs.open(argv[1], 'r', 'utf-8')
- for line in input.readlines():
- try: tweet = json.loads(line)
- except: continue
- if tweet['geo']:
- #if tweet['geo']['type'] == 'Point':
- when = calendar.timegm(time.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y'))
- #print when
- ago = time.time() - when
- lat, lon = tweet['geo']['coordinates']
- y = int((lat-latrange[0]) * 1/latgrain)
- x = int((lon-lonrange[0]) * 1/longrain)
- y = height-y
- try:
- pixels[x, y] = kz1(ago/(60*60*24) + 0.5)
- #pixels[x, y] += colorincrement
- except:
- print when, x, y
- #pass
- i = invert(i)
- i.save(argv[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement