Thursday, July 16, 2015

[RPI] Yicam - Resize - Tweet via Raspberry Pi

16 July 2015

RPI Config for live image Yicam - Rpi - Resize - Tweet

sudo apt-get install python-setuptools
sudo easy_install pip
sudo apt-get install libjpeg-dev
sudo pip-3.2 install pillow
sudo pip-3.2 install TwitterApi

Gunakan pyton3 command

python3 yirestwet.py
from __future__ import print_function
import os, re, sys, time, socket, json
import urllib.request
from TwitterAPI import TwitterAPI
from PIL import Image
def capture():
host = "192.168.42.1"
port = 7878
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(str.encode('{"msg_id": 257,"token": 0}'))
data = s.recv(512)
ddata = data.decode('utf-8')
#print (ddata)
if "rval" in ddata:
token = re.findall('"param": (.+) }',ddata)[0]
else:
data = s.recv(512)
ddata = data.decode('utf-8')
if "rval" in ddata:
token = re.findall('"param": (.+) }',ddata)[0]
tosend = '{"msg_id":769,"token":%s}' %token
tos = str.encode(tosend)
s.send(tos)
s.recv(512)
data = s.recv(512)
data = s.recv(512)
ddata = data.decode('utf-8')
f = json.loads(ddata)
filename = re.split("(/)", f['param'], 3)
img = 'http://192.168.42.1/'+filename[6]
return img
def tweet(stat,img):
consumer_key = "____";
consumer_secret = "____";
access_token_key = "____";
access_token_secret = "____";
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)
#r = api.request('statuses/update', {'status':'Hello world from py'})
#print (r.status_code)
TWEET_TEXT = stat
IMAGE_PATH = img
#IMAGE_URL = img
#file = urllib.request.urlopen(IMAGE_URL)
file = open(IMAGE_PATH, 'rb')
data = file.read()
r = api.request('statuses/update_with_media',
{'status': TWEET_TEXT},
{'media[]': data})
print (r.status_code)
#print('SUCCESS' if r.status_code == 200 else 'FAILURE')
def resimg(path):
infile = urllib.request.urlopen(path)
size = (1024, 1024)
im = Image.open(infile)
im.thumbnail((size))
im.save('tmp.jpg', "JPEG")
return 'tmp.jpg'
path = capture()
img = resimg(path)
stat = ''
tweet(stat,img)
view raw yirestwet.py hosted with ❤ by GitHub

Referensi
- http://stackoverflow.com/questions/8915296/python-image-library-fails-with-message-decoder-jpeg-not-available-pil
- http://pi-camera.blogspot.com/p/raspberry-pi-setup.html
- https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=97326
- https://github.com/deltaflyer4747/Xiaomi_Yi/blob/master/Standalone_scripts/Camera_photo.py
- http://copter.sovgvd.info/a/Xiaomi-Yi-protocol-remote-control
- https://www.youtube.com/watch?v=WrtebUkUssc
- https://gist.github.com/capung48/0f2f73d599f2de8100eb

1 comment:

  1. Harrah's Cherokee Casino & Hotel - MapYRO
    Find worrione.com your way 출장안마 around the casino, find where everything is located sol.edu.kg with the most up-to-date information about Harrah's Cherokee 토토 사이트 Casino & Hotel in wooricasinos.info Cherokee, NC.

    ReplyDelete