Browse Source

Automatically retry to fetch data

Since emojipedia almost never answers on the first try (or ever 😢), the
scripts now re-tries up to five times and prints an error if it didn't
work. If this keep happening, I'll have to think of something.
tags/1.3.0
Fabian Winter 2 years ago
parent
commit
7a8448141e
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      extract_emojis.py

+ 10
- 1
extract_emojis.py View File

@@ -1,7 +1,16 @@
import requests
from bs4 import BeautifulSoup

data = requests.get('https://emojipedia.org/emoji/') # type: requests.Response
max_tries = 5
for i in range(max_tries):
data = requests.get('https://emojipedia.org/emoji/') # type: requests.Response
if data:
break

if not data:
print("Could not fetch emoji data. Try again later or use another URL.")
exit(10)

soup = BeautifulSoup(data.content, 'lxml') # type: BeautifulSoup

python_file = open('emojis.py', 'w')

Loading…
Cancel
Save