SatSale

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

paynym.py (2335B)


      1 import requests
      2 import logging
      3 
      4 paynym_site = "https://paynym.is/"
      5 
      6 
      7 def get_paynym(nym):
      8     if nym is None:
      9         return None
     10 
     11     r = requests.get(paynym_site + nym)
     12 
     13     if r.status_code == 200:
     14         nym_html = r.text
     15         nym_html = nym_html.split('<span class="paycode">')[1].split("</span>")[0]
     16         return nym_html
     17 
     18 
     19 def insert_paynym_html(nym):
     20     donate_file = "templates/donate.html"
     21     with open(donate_file, "r") as f:
     22         donate_html = f.read()
     23 
     24     if 'class="paynym"' in donate_html:
     25         logging.info("Found existing paynym HTML in donate.html.")
     26         return
     27 
     28     payment_code = get_paynym(nym)
     29     avatar_url = paynym_site + "{}/avatar".format(payment_code)
     30     codeimage_url = paynym_site + "{}/codeimage".format(payment_code)
     31 
     32     logging.info("Fetching paynym images...")
     33 
     34     avatar_data = requests.get(avatar_url).content
     35     with open("static/avatar.png", "wb") as f:
     36         f.write(avatar_data)
     37 
     38     codeimage_data = requests.get(codeimage_url).content
     39     with open("static/codeimage.png", "wb") as f:
     40         f.write(codeimage_data)
     41 
     42     css_html = """
     43     <style>
     44         .paynym {
     45           position: relative;
     46           float: left;
     47         }
     48 
     49         .paynym .hoverImg {
     50           position: absolute;
     51           left: 0;
     52           top: 0;
     53           display: none;
     54         }
     55 
     56         .paynym:hover .hoverImg {
     57           display: block;
     58           }
     59     </style>
     60     """
     61 
     62     nym_html = (
     63         """
     64     <div class="paynym">
     65         <div class="imageInn">
     66             <img width="100px" style="border-radius:50px;" src="{{ url_for('static', filename='avatar.png') }}">
     67         </div>
     68         <div class="hoverImg">
     69             <img width="100px" src="{{ url_for('static', filename='codeimage.png') }}">
     70         </div>
     71         """
     72         + """
     73         <small style="vertical-align:middle"><a href="{}" target="_blank">{}</a></small>
     74         """.format(
     75             paynym_site + nym, nym
     76         )
     77         + """
     78     </div>
     79     <br>
     80     """
     81     )
     82 
     83     modified_html = donate_html.replace("</head>", css_html + "\n</head>")
     84     modified_html = modified_html.replace(
     85         '<div id="paymentForm">', nym_html + '\n\t<div id="paymentForm">'
     86     )
     87 
     88     with open(donate_file, "w") as f:
     89         f.write(modified_html)
     90 
     91     logging.info("Wrote donate.html with paynym tags")
     92 
     93     return