release
This commit is contained in:
parent
05c12b3977
commit
a3fa54e67d
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
.venv/
|
venv/
|
||||||
*~
|
words.db
|
||||||
|
|
||||||
|
2
CHANGELOG.md
Normal file
2
CHANGELOG.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# 1.0.0 (2021-02-22)
|
||||||
|
+ Release version
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Alexander Popov
|
Copyright (c) 2021 Alexander Popov
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
59
grab.py
Executable file
59
grab.py
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
|
import sqlite3
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
__author__ = 'Alexander Popov'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__version__ = '1.0.0'
|
||||||
|
__email__ = 'iiiypuk@fastmail.fm'
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# dict for new parsed words
|
||||||
|
words = {}
|
||||||
|
|
||||||
|
# open datebase
|
||||||
|
db = sqlite3.connect('./words.db')
|
||||||
|
cursor = db.cursor()
|
||||||
|
|
||||||
|
# create new table if not exist
|
||||||
|
try:
|
||||||
|
cursor.execute('CREATE TABLE words(word text, definition text)')
|
||||||
|
except sqlite3.OperationalError as e:
|
||||||
|
print('INFO:', e)
|
||||||
|
|
||||||
|
# start parse words
|
||||||
|
try:
|
||||||
|
while(True):
|
||||||
|
sleep(0.5)
|
||||||
|
|
||||||
|
new_word = parse()
|
||||||
|
words[new_word['word']] = new_word['definition']
|
||||||
|
|
||||||
|
print('Parsed', new_word['word'])
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
for word in words:
|
||||||
|
cursor.execute(
|
||||||
|
'INSERT INTO words VALUES ("{word}", "{defin}")'
|
||||||
|
.format(word=word, defin=words[word]))
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
print('Saved %d words.' % len(words))
|
@ -1,58 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
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__ = "MIT"
|
|
||||||
__version__ = "1.0.1"
|
|
||||||
__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))
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user