Skip to content

Instantly share code, notes, and snippets.

@MayankPratap
Created May 1, 2017 08:50
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 MayankPratap/2e070039722e26ee5ecf210ca94c3f45 to your computer and use it in GitHub Desktop.
Save MayankPratap/2e070039722e26ee5ecf210ca94c3f45 to your computer and use it in GitHub Desktop.
Code that will send image to bot server.
import requests
import json
import random
import codecs
#import cStringIO
import base64
from base64 import b64encode
#import pyimgur
#import picamera
import pickle
import http
from bs4 import BeautifulSoup
import xml.etree.ElementTree
from time import sleep
# BeautifulSoup is used to parse XML that is returned by imageshack api after
# uploading pic. We parse it to get image_link of uploaded image.
# Using imageshack endpoints
url="https://post.imageshack.us/upload_api.php"
api_key="DEGHSVWY76e25bee3b8a24d32568a646e4657e9b"
image_url="http://orig03.deviantart.net/c543/f/2011/103/4/7/mystic____gohan_by_drozdoo-d3dxa17.png"
try:
f=open('elonmusk.jpg','rb')
print(f.name)
print(f.mode)
#r=requests.post(url,params={'key':api_key,'url': image_url,'format':json})
params={'key':api_key,'fileupload':f ,'format':json}
#params=json.dumps(params)
#datagen, headers = multipart_encode(params)
#headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0' }
r=requests.post(url,params=params)
x=r.text # xml returned
#print(type(x))
print(x)
y=BeautifulSoup(x,"lxml")
var=y.imginfo.links.image_link
var=str(var)
image_url=var[12:-13]
print(image_url)
url2='https://fe964296.ngrok.io/gotsomepic'
data={'image_url':image_url}
data=json.dumps(data)
r=requests.post(url2,data=data)
#print(r.text)
#print("Raula")
#sleep(1)
print("Getting user's reply")
url2='https://fe964296.ngrok.io/userReply'
r=requests.get(url2)
#cnt=0
#userNotReply=True
while r.text=="":
sleep(4)
#cnt+=1
r=requests.get(url2)
print(r.text)
except http.client.HTTPException as error:
print(error)
#print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment