Created
August 13, 2016 12:59
-
-
Save ChiChou/d3d90b026f45017a98e8e39157d3caae to your computer and use it in GitHub Desktop.
How I name my project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# git clone https://github.com/dwyl/english-words.git | |
# cd english-words | |
# wget https://gist.github.com/ChiChou/d3d90b026f45017a98e8e39157d3caae/raw/nameit.py | |
# pip3 install lxml beautifulsoup4 requests | |
# ./nameit.py | |
import random | |
import os | |
import requests | |
from bs4 import BeautifulSoup | |
wordlists = ('words.txt', 'words2.txt', 'words3.txt') | |
filename = random.choice(wordlists) | |
size = os.path.getsize(filename) | |
with open(filename) as f: | |
offset = random.randint(0, size) | |
f.seek(offset) | |
drop, word, *_ = f.read(64).split('\n') | |
print(word) | |
r = requests.get('http://cn.bing.com/dict/search', params={'q': word}) | |
bs = BeautifulSoup(r.text, 'lxml') | |
definition = bs.select('.qdef ul li') | |
if not len(definition): | |
print('(未找到可用翻译)') | |
for li in definition: | |
print(' | '.join([li.select(selector)[0].text for selector in ('.pos', '.def')])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment