Skip to content

Instantly share code, notes, and snippets.

@FrancoMuniz
Created September 14, 2019 22:58
Show Gist options
  • Save FrancoMuniz/1cbba6e71adbc37a4ef728afc297b109 to your computer and use it in GitHub Desktop.
Save FrancoMuniz/1cbba6e71adbc37a4ef728afc297b109 to your computer and use it in GitHub Desktop.
Dolar Blue - A real time currency bot that updates the price on a Telegram Channel
import sys
from urllib.request import urlopen
import time
import string
import telebot
import json
import pymongo
import re
uri = 'insertyourmongodburlhere'
def main():
client = pymongo.MongoClient(uri)
db = client.get_default_database()
infoCollection = db['previousInfo']
while True:
infoCol = infoCollection.find_one()
lastPrice = infoCol['lastPrice']
priceData = get_data()
currentPrice = priceData[0]
if lastPrice != currentPrice:
trendEmoji = '\u2B06' if currentPrice > lastPrice else '\u2B07'
bot = telebot.TeleBot(token = "insertyourtelegrambotkeyhere")
bot.send_message(chat_id = "@insertyourchannelnamehere", text = "%s Dólar Blue: $%.2f (Antes: $%.2f)" % (trendEmoji, currentPrice, lastPrice))
myquery = { "lastPrice": lastPrice }
infoCollection.delete_one(myquery)
mynewdata = { "lastPrice": currentPrice }
infoCollection.insert_one(mynewdata)
time.sleep(5)
def get_data():
f = urlopen('http://api.bluelytics.com.ar/v2/latest')
data = f.read()
dataList = json.loads(data)
blue_sell = dataList['blue']['value_sell']
blue_buy = dataList['blue']['value_buy']
blue_avg = dataList['blue']['value_avg']
return[blue_sell, blue_buy, blue_avg]
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment