221 |
222 | NOT: Bu adrese yaptığımız istek ile Telegram botumuzla ilgili tüm gelişmeleri gözlemliyoruz.
223 | Örneğin; biri botunuza mesaj attığı zaman mesaj atan kişinin adını, ne mesaj yazdığını ve chat_id değerini buradan görebilirsiniz.
224 |
225 | 4. Python ile bota mesaj göndermek
226 | ```python
227 | >>> import telegram
228 | >>> bot = telegram.Bot(token='BOT_TOKEN')
229 | >>> bot.send_message(USER_ID, "Merhaba!")
230 | ```
231 | 5. Dosyaya uygulamayı koymak
232 | 6. Dolar değeri Euro değerinden büyükse botun mesaj göndermesi
233 |
234 | ```python
235 | import requests
236 | import telegram
237 | import time
238 |
239 | bot = telegram.Bot(token='TELEGRAM_TOKEN_BURAYA')
240 |
241 | base_currency = 6
242 |
243 | while True:
244 | response = requests.get(f"https://api.collectapi.com/economy/exchange?int={base_currency}&to=USD&base=EUR",
245 | headers = {
246 | "content-type": "application/json",
247 | "authorization": "apikey COLLECTAPI_TOKEN_BURAYA"
248 | }
249 | )
250 |
251 | json = response.json()
252 | exchange_data = json["result"]["data"][0]
253 | calculated_dollar = exchange_data["calculated"]
254 |
255 | if calculated_dollar > base_currency:
256 | bot.send_message(TELEGRAM_CHAT_ID_DEGERI, f"{str(base_currency)} Euro'nun Dolar karşılığı {str(calculated_dollar)} $ dır")
257 | time.sleep(30)
258 | ```
259 |
260 | Python Öğren - Python'a 4 Saatte Başlangıç
261 | Eğitmenler: Güray Yıldırım, Aylin Gümüş, Muhammed Taha Ayan
262 |
--------------------------------------------------------------------------------
/README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peptr/python-ogren-4-saatte-python-baslangic/3e2d701b8a05128b4b924b5373bcfdd200e99a55/README.pdf
--------------------------------------------------------------------------------
/requests-doviz.py:
--------------------------------------------------------------------------------
1 | import requests # Requests modülü import edildi
2 | import json
3 | import telegram
4 | import time
5 |
6 | bot = telegram.Bot(token="")
7 |
8 | base_currency = 1000
9 |
10 | while True:
11 | sonuc = requests.get(
12 | f"https://api.collectapi.com/economy/currencyToAll?int={base_currency}&base=TRY",
13 |
14 | headers={
15 | "content-type": "application/json",
16 | "authorization": "apikey "
17 | }
18 | )
19 |
20 | json = sonuc.json()
21 | success = json["success"]
22 | results = json["result"]["data"] # List
23 |
24 | for result in results: # For döngüsü ile listenin her elemanı sırayla result değişkenine atandı
25 | if result["code"] == "USD": # Eğer listede sıradaki eleman dolarsa işlem yapılacak
26 | calculated_dollar = result["calculated"] # Number
27 | string = result["calculatedstr"] # String
28 |
29 | print("$" + string) # $123.45
30 |
31 | # print(result["calculated"])
32 | # print(result["calculatedstr"])
33 |
34 | if calculated_dollar > base_currency:
35 | bot.send_message("", f"{str(base_currency)} €'nun karşılığı {str(calculated_dollar)} $'dır")
36 | time.sleep(30) # 30 saniye bekliyoruz
37 |
38 | # print(results[0]) # Listedeki ilk eleman
39 | # print(len(json)) # 2
40 | # print(success) # True
41 | # print(len(results)) # 167
42 | # print(sonuc) # 200 Object
43 | # print(sonuc.text) # String
44 | # print(sonuc.json()) # JSON Object
45 | # print(json) # JSON Object
46 | # print(json.dumps(sonuc.json())) # String
--------------------------------------------------------------------------------