init
This commit is contained in:
parent
ba3dda1164
commit
e7eda34aa6
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Alexander Popov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
55
randomword_grabber.py
Normal file
55
randomword_grabber.py
Normal file
@ -0,0 +1,55 @@
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
import json
|
||||
from time import sleep
|
||||
|
||||
|
||||
def load_words():
|
||||
with open('./words.json', encoding='utf-8') as file:
|
||||
words = json.load(file, encoding='utf-8')
|
||||
|
||||
return(words)
|
||||
|
||||
|
||||
def parse():
|
||||
r = requests.get('https://randomword.com/')
|
||||
data = r.text
|
||||
soup = BeautifulSoup(data, 'html.parser')
|
||||
word = soup.find('div', {'id': 'random_word'}).text
|
||||
word_definition = soup.find('div', {'id': 'random_word_definition'}).text
|
||||
|
||||
new_word = {'word': word, 'definition':
|
||||
[word_definition.replace(' ', '')]}
|
||||
|
||||
return(new_word)
|
||||
|
||||
|
||||
def main(words_data):
|
||||
while(True):
|
||||
sleep(0.5)
|
||||
new_word = parse()
|
||||
|
||||
print(new_word)
|
||||
|
||||
words_data[new_word['word']] = new_word['definition']
|
||||
|
||||
return(words_data)
|
||||
|
||||
__author__ = 'Alexander Popov'
|
||||
__license__ = "Public Domain"
|
||||
__version__ = "1.0.0"
|
||||
__email__ = "iiiypuk@fastmail.fm"
|
||||
|
||||
if __name__ == '__main__':
|
||||
words = {}
|
||||
|
||||
words = load_words()
|
||||
try:
|
||||
while(True):
|
||||
words = main(words)
|
||||
except KeyboardInterrupt:
|
||||
with open('./words.json', 'w', encoding='utf-8') as file:
|
||||
file.write(
|
||||
json.dumps(words, indent=4, ensure_ascii=False))
|
||||
|
||||
print('Saved %d words.' % len(words))
|
Loading…
Reference in New Issue
Block a user