Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SQLHelper
- import io
- import requests
- import imagehash
- from PIL import Image
- import re
- import csv
- import logging
- photopath = "http://cbr.ru/legacy/PhotoStore/img/"
- descpath = "http://cbr.ru/cash_circulation/memorable_coins/coins_base/ShowCoins/?cat_num="
- ML = ["ММД", "ЛМД", "СПМД"]
- def main():
- logging.basicConfig(filename="coinsparse.log", level=logging.INFO)
- db = SQLHelper.SQLHelper("test.db")
- coins = db["coins"]("id", "cat_number")
- csfile = open("coinhash.csv", "w", newline="")
- csw = csv.writer(csfile, dialect="excel", delimiter =";")
- csw.writerow(["id","cat_number","mint"])
- for coin in coins:
- try:
- # hash = imagehash.phash(Image.open(io.BytesIO(requests.get(f"{photopath}{coin[1]}r.jpg").content)))
- mintstring =""
- page = requests.get(descpath+coin[1]).text
- mint = re.search("Чеканка:(.+?)[\.<]",page)
- if mint:
- mint = mint.group(1).strip()
- mintstring = ",".join(filter(lambda x: x in mint, ML))
- print(f"{coin[0]} - {mintstring}")
- csw.writerow([coin[0], coin[1], mintstring])
- except Exception:
- logging.info("Error parsing cat_number :"+coin[1])
- csfile.close()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment