├── Procfile ├── requirements.txt ├── config.py ├── __pycache__ ├── config.cpython-38.pyc └── upload.cpython-38.pyc ├── upload.py ├── README.md └── main.py /Procfile: -------------------------------------------------------------------------------- 1 | web: python3 main.py 2 | worker: python3 main.py -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.24.0 2 | webscreenshot==2.9 3 | python_telegram_bot==12.5.1 4 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | class Config(object): 2 | CLIENT_ID = "" 3 | BOT_TOKEN = "" 4 | HEROKU_APP_NAME = "" -------------------------------------------------------------------------------- /__pycache__/config.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1337w0rm/ReverseImageSearch/HEAD/__pycache__/config.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/upload.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1337w0rm/ReverseImageSearch/HEAD/__pycache__/upload.cpython-38.pyc -------------------------------------------------------------------------------- /upload.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from config import Config 3 | from os import remove 4 | 5 | def upload(): 6 | 7 | headers = {'Authorization': 'Client-ID %s' % Config.CLIENT_ID} 8 | 9 | info = { 10 | 'type': 'file', 11 | 'title': 'screenSearch Screenshot', 12 | 'description': 'image uploaded by the screenSearch project' 13 | } 14 | 15 | 16 | image = {'image':open('ss.jpg','rb')} 17 | 18 | response = requests.post("https://api.imgur.com/3/upload", 19 | json=info, 20 | headers=headers, 21 | files=image) 22 | 23 | remove('ss.jpg') 24 | return response.json()['data']['link'] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReverseImageSearch 2 | 3 | [![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger) 4 | 5 | Reverse Image Search is a Telegram Bot which do reverse image seraches for you. It has ```Yandex``` and ```Google``` reverse image search. Just send an image to the Bot and reply to that image with ```/yfind``` for Yandex search and ```/gfind``` for Google Search it'll reply back to you with a screenshot of the search and URL to the search results so that you can check the results manually. 6 | 7 | ## Installation 8 | 9 | #### 1. On Local System 10 | 11 | ```sh 12 | $ git clone https://github.com/1337w0rm/ReverseImageSearch.git 13 | $ cd ReverseImageSearch 14 | $ pip install -r requirements.txt 15 | ``` 16 | - Open ```config.py``` file in any text editor. 17 | - Put Imgur API client_id in ```CLIENT_ID``` variable 18 | - Put your Bot Token in ```TELEGRAM_ACCESS_TOKEN``` variable. 19 | 20 | - Run 21 | ``` 22 | python main.py 23 | ``` 24 | 25 | #### 2. On Install Heroku 26 | 27 | - Clone this repository on your local system 28 | ``` 29 | git clone https://github.com/1337w0rm/ReverseImageSearch.git 30 | cd ReverseImageSearch 31 | pip install -r requirements.txt 32 | ``` 33 | - Install [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) 34 | - Login to your account with the below command 35 | 36 | ``` 37 | heroku login 38 | ``` 39 | - Create a new heroku app: 40 | ``` 41 | heroku create appname 42 | ``` 43 | - Goto the ReverseImageSearch directory, select this app that you creted using Heroku-CLI 44 | ``` 45 | heroku git:remote -a appname 46 | ``` 47 | - Open ```config.py``` in any text editor 48 | - Add your Bot Token to ```TELEGRAM_ACCESS_TOKEN``` variable 49 | - Add Heroku app name to ```HEROKU_APP_NAME``` variable 50 | - Add Imgur API client_id in ```CLIENT_ID``` variable 51 | 52 | - Add all the files to staging. 53 | ``` 54 | git add . 55 | ``` 56 | - Commit new changes: 57 | ``` 58 | git commit -m "First Push" 59 | ``` 60 | - Push Code to Heroku: 61 | ``` 62 | git push heroku master 63 | ``` 64 | - Enable Heroku Dyno 65 | ``` 66 | heroku ps:scale web=1 67 | ``` 68 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import logging 3 | from telegram.ext import Updater, CommandHandler 4 | from config import Config 5 | from upload import upload 6 | from webscreenshot.webscreenshot import * 7 | import argparse 8 | from glob import glob 9 | 10 | 11 | 12 | #Logger 13 | logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 14 | level=logging.INFO) 15 | 16 | 17 | updater = Updater(token = Config.BOT_TOKEN, use_context=True) 18 | dp = updater.dispatcher 19 | 20 | mode="prod" 21 | 22 | if mode == "dev": 23 | def run(updater): 24 | updater.start_polling() 25 | elif mode == "prod": 26 | def run(updater): 27 | PORT = int(os.environ.get("PORT", "8443")) 28 | # Code from https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#heroku 29 | updater.start_webhook(listen="0.0.0.0", 30 | port=PORT, 31 | url_path=Config.BOT_TOKEN) 32 | updater.bot.set_webhook("https://{}.herokuapp.com/{}".format(Config.HEROKU_APP_NAME, Config.BOT_TOKEN)) 33 | 34 | 35 | 36 | def yfind(update, context): 37 | fileId = update.message.reply_to_message.photo[0].file_id 38 | file = context.bot.getFile(fileId) 39 | file.download('ss.jpg') 40 | 41 | imageLink = upload() 42 | 43 | query = list() 44 | query.append("https://yandex.com/images/search?url=" + imageLink + "&rpt=imageview") 45 | 46 | options = argparse.Namespace(URL=None, ajax_max_timeouts='1400,1800', cookie=None, crop="10,20,w,h", format='png', header=None, http_password=None, http_username=None, imagemagick_binary=None, input_file=None, label=False, label_bg_color='NavajoWhite', label_size=60, log_level='NOTSET', multiprotocol=False, no_xserver=False, output_directory='screenshots', port=None, proxy=None, proxy_auth=None, proxy_type=None, quality=75, renderer='phantomjs', renderer_binary=None, ssl=False, timeout=30, verbosity=2, window_size='1200,800', workers=1) 47 | take_screenshot(query, options) 48 | 49 | for i in glob('screenshots/*.png'): 50 | try: 51 | context.bot.send_photo(chat_id=update.message.chat_id, photo=open(i, 'rb'), caption=query[0], timeout = 120) 52 | os.remove(i) 53 | except : 54 | context.bot.send_document(chat_id=update.message.chat_id, document=open(i, 'rb'), caption=query[0], timeout = 120) 55 | os.remove(i) 56 | def gfind(update, context): 57 | fileId = update.message.reply_to_message.photo[0].file_id 58 | file = context.bot.getFile(fileId) 59 | file.download('ss.jpg') 60 | 61 | imageLink = upload() 62 | 63 | query = list() 64 | query.append("https://images.google.com/searchbyimage?image_url=" + imageLink) 65 | 66 | options = argparse.Namespace(URL=None, ajax_max_timeouts='1400,1800', cookie=None, crop="5,20,w,h", format='png', header=None, http_password=None, http_username=None, imagemagick_binary=None, input_file=None, label=False, label_bg_color='NavajoWhite', label_size=60, log_level='NOTSET', multiprotocol=False, no_xserver=False, output_directory='screenshots', port=None, proxy=None, proxy_auth=None, proxy_type=None, quality=75, renderer='phantomjs', renderer_binary=None, ssl=False, timeout=30, verbosity=2, window_size='1200,800', workers=1) 67 | take_screenshot(query, options) 68 | 69 | for i in glob('screenshots/*.png'): 70 | try: 71 | context.bot.send_photo(chat_id=update.message.chat_id, photo=open(i, 'rb'), caption=query[0], timeout = 120) 72 | os.remove(i) 73 | except : 74 | context.bot.send_document(chat_id=update.message.chat_id, document=open(i, 'rb'), caption=query[0], timeout = 120) 75 | os.remove(i) 76 | 77 | 78 | 79 | def main(): 80 | dp.add_handler(CommandHandler("yfind", yfind)) 81 | dp.add_handler(CommandHandler("gfind", gfind)) 82 | logging.info("Bot started") 83 | run(updater) 84 | 85 | if __name__ == '__main__': 86 | main() --------------------------------------------------------------------------------