Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-cavano committed May 6, 2022
1 parent c4f70e7 commit 970dcdb
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import requests
import schedule
import csv
import json
import time
from datetime import datetime
from bs4 import BeautifulSoup


def job():

url1 = requests.get('https://coinmarketcap.com/pt-br/currencies/bitcoin/')
#print(url1.status_code)
htmlBruto1 = url1.content
site = BeautifulSoup(htmlBruto1, 'html.parser')
htmlBruto = url1.content
site = BeautifulSoup(htmlBruto, 'html.parser')
tagPreco = site.find('div', attrs={'class':'priceValue smallerPrice'})
#print(tagPreco)
preco = tagPreco.find('span')

time = datetime.now()

dict_1 = {
"preco" : preco.text,
"data" : time,
time = str(datetime.now())

url = "https://data.mongodb-api.com/app/data-pkmib/endpoint/data/beta/action/insertOne"
payload = json.dumps({
"collection": "testea",
"database": "teste",
"dataSource": "Cluster0",
"document": {
"preço": preco.text,
"horario": time
}
})
headers = {
'Content-Type': 'application/json',
'Access-Control-Request-Headers': '*',
'api-key': 'bWdELScAUp4oSoDmVLyoOPIKosx0VqCpJpQdlgzuWq9HW2R8MqRXNDcyxLtpB59A'
}
print()
print(dict_1)
print()
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

schedule.every(2).minutes.do(job)

#schedule.every(2).minutes.do(job)
schedule.every(5).seconds.do(job)

while True:
schedule.run_pending()
#time.sleep(0)
time.sleep(0)

0 comments on commit 970dcdb

Please sign in to comment.