Skip to content

Instantly share code, notes, and snippets.

@motebaya
Last active August 1, 2022 08:44
Show Gist options
  • Save motebaya/6d9a7e33591247a9723e862dab2b4d20 to your computer and use it in GitHub Desktop.
Save motebaya/6d9a7e33591247a9723e862dab2b4d20 to your computer and use it in GitHub Desktop.
snippet python for get readable word
"""
here you can get list world for variable names
"""
import requests
import re
from urllib.parse import urlparse
def animal(f):
if (indoAnimal := re.findall(r"(?<=\">)([\w+]*?)(?=<\/a><\/td>)", requests.get("https://foresteract.com/daftar-nama-hewan-binatang-di-indonesia/").text)):
f.write("\n".join(map((lambda x: x.lower().strip()),indoAnimal)) + "\n")
def flower(f):
if (indoFlower := re.findall(r"(?<=<\/span>)([\w\s]+?)(?=\s+=\s+|\<span)", requests.get("https://generasibiologi.com/2016/09/daftar-nama-latin-ilmiah-tumbuhan.html").text)):
f.write("\n".join(filter((lambda x: x), map((lambda x: "_".join(x.split()).lower() if x.istitle() else ""), indoFlower))) + "\n")
def country(f):
data = []
tolower = (lambda x: "_".join(x.split()).lower())
page = requests.get("https://www.worldometers.info/geography/how-many-countries-are-there-in-the-world/")
if (counts := re.findall(r"(?<=left\">\<a\shref\=\")(.*?)\">(.*?)(?=<\/a><\/td>)", page.text)):
for url, names in counts:
print(names)
f.write(tolower(names) + "\n")
if (city := re.findall(r"(?<=5px\">)([\w+]*?)(?=<\/td>)", requests.get("https://{}/{}".format(urlparse(page.url).netloc, url)).text)):
f.write("\n".join(
list(
map(
(lambda x: tolower(x)), city
)
)
) + "\n")
print("\n".join(city))
else:
continue
if __name__=="__main__":
with open("word.txt","a") as f:
animal(f)
flower(f)
country(f)
f.close()
print("ok all done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment