sunsexsurf

mint_checker

Apr 14th, 2020
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. import SQLHelper
  2. import io
  3. import requests
  4. import imagehash
  5. from PIL import Image
  6. import re
  7. import csv
  8. import logging
  9.  
  10. photopath = "http://cbr.ru/legacy/PhotoStore/img/"
  11. descpath = "http://cbr.ru/cash_circulation/memorable_coins/coins_base/ShowCoins/?cat_num="
  12. ML = ["ММД", "ЛМД", "СПМД"]
  13.  
  14. def main():
  15.     logging.basicConfig(filename="coinsparse.log", level=logging.INFO)
  16.     db = SQLHelper.SQLHelper("test.db")
  17.     coins = db["coins"]("id", "cat_number")
  18.     csfile = open("coinhash.csv", "w", newline="")
  19.     csw = csv.writer(csfile, dialect="excel", delimiter =";")
  20.     csw.writerow(["id","cat_number","mint"])
  21.     for coin in coins:
  22.         try:
  23.             # hash = imagehash.phash(Image.open(io.BytesIO(requests.get(f"{photopath}{coin[1]}r.jpg").content)))
  24.             mintstring =""
  25.             page = requests.get(descpath+coin[1]).text
  26.             mint = re.search("Чеканка:(.+?)[\.<]",page)
  27.             if mint:
  28.                 mint = mint.group(1).strip()
  29.                 mintstring = ",".join(filter(lambda x: x in mint, ML))
  30.             print(f"{coin[0]} - {mintstring}")
  31.             csw.writerow([coin[0], coin[1], mintstring])
  32.         except Exception:
  33.             logging.info("Error parsing cat_number :"+coin[1])
  34.     csfile.close()
  35.  
  36. if __name__ == "__main__":
  37.     main()
Advertisement
Add Comment
Please, Sign In to add comment