python类create()的实例源码

wxbot.py 文件源码 项目:raspberrypi_api 作者: wwj718 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def gen_qr_code(self, qr_file_path):
        string = 'https://login.weixin.qq.com/l/' + self.uuid
        qr = pyqrcode.create(string)
        if self.conf['qr'] == 'png':
            qr.png(qr_file_path, scale=8)
            show_image(qr_file_path)
            # img = Image.open(qr_file_path)
            # img.show()
        elif self.conf['qr'] == 'tty':
            print(qr.terminal(quiet_zone=1))
cli.py 文件源码 项目:sporestack-python 作者: sporestack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def handle_payment(uuid, address, satoshis, wallet_command, currency):
    """
    Payment handling routine for spawn and topup.
    """
    if wallet_command is not None:
        full_wallet_command = '{} {} {} >&2'.format(wallet_command,
                                                    address,
                                                    satoshis)
        if os.system(full_wallet_command) != 0:
            raise
        return True
    amount = "{0:.8f}".format(satoshis *
                              0.00000001)
    if currency == 'btc':
        uri = 'bitcoin:{}?amount={}'.format(address, amount)
    elif currency == 'bch':
        uri = 'bitcoincash:{}?amount={}'.format(address, amount)
    else:
        raise ValueError('Currency must be one of: btc, bch')
    premessage = '''UUID: {}
Bitcoin URI: {}
Pay with Bitcoin *within an hour*. QR code will change every so often but the
current and previous QR codes are both valid for about an hour. The faster you
make payment, the better. Pay *exactly* the specified amount. No more, no less.
Resize your terminal and try again if QR code above is not readable.
Press ctrl+c to abort.'''
    message = premessage.format(uuid, uri)
    qr = pyqrcode.create(uri)
    stderr(qr.terminal(module_color='black',
                       background='white',
                       quiet_zone=1))
    stderr(message)
views.py 文件源码 项目:MusicQR 作者: tangziyi001 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def getQRCode(request, music_id):
    # generate token - save to database
    # generate URL with token --> this will be a QR code to be displayed
    newMusic = Music.objects.get(id=music_id)
    stringToHash = str(time.time()) + str(newMusic.artist) + str(newMusic.title)
    h = hashlib.sha1()
    h.update(stringToHash)    
    tokenToAppendinURL = str(h.hexdigest())

    # save music query to database 
    newQuery = MusicQuery(query=newMusic, token=tokenToAppendinURL)
    newQuery.save()

    #QR code to be displayed
    # url = pyqrcode.create('http://35.163.220.222:8000/musician/music/' + tokenToAppendinURL)
    # url = pyqrcode.create('http://54.209.248.145:8000/musician/music/' + tokenToAppendinURL)
    # url = pyqrcode.create('http://localhost:8000/musician/music/' + tokenToAppendinURL)
    url = pyqrcode.create(settings.ROOT_URL + '/musician/music/' + tokenToAppendinURL)

    # image_as_str = code.png_as_base64_str(scale=5)
    # html_img = '<img src="data:image/png;base64,{}">'.format(image_as_str)
    strToSave = 'musician/static/images/' + tokenToAppendinURL + '.png'
    url.png(strToSave, scale=6)  
    strToShow = '/static/images/' + tokenToAppendinURL + '.png'
    x = json.dumps({'qrpath': strToShow})
    return JsonResponse(x, safe=False)

# executed on QR code url
views.py 文件源码 项目:MusicQR 作者: tangziyi001 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def download(request, token):
    context = {}
    if request.method == 'GET':
        try:
            # check token in database and retrieve corresponding music
            targetQuery = MusicQuery.objects.get(token=token)
            targetMusic = targetQuery.query
            file_name = targetMusic.file_name
            dir_path = os.path.dirname(os.path.realpath(__file__))
            file_path = dir_path + '/music/' + file_name
            file_wrapper = FileWrapper(file(file_path, 'rb'))
            file_mimetype = mimetypes.guess_type(file_path)

            # store the download record
            newDownload = Download.objects.create(music=targetMusic, download_loc='')
            newDownload.save()

            # download the music file
            response = HttpResponse(file_wrapper, content_type=file_mimetype)
            response['X-Sendfile'] = file_path
            response['Content-Length'] = os.stat(file_path).st_size
            response['Content-Disposition'] = 'attachment; filename=' + file_name
            targetQuery.delete()
            return response
        except Exception as e:
            messages.add_message(request, messages.ERROR, "Music Download Failed: QR Code Expired")
            logging.exception("message")
            return redirect('/musician')
    else:
        return redirect('/musician')

# artist upload handler
default.py 文件源码 项目:script.kodi.loguploader 作者: XBMC-Addons 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def showResult(self, message, url=None):
        if url:
            imagefile = os.path.join(xbmc.translatePath(PROFILE),'%s.png'%str(url.split('/')[-2]))
            qrIMG = pyqrcode.create(url)
            qrIMG.png(imagefile, scale=10)
            qr = QRCode( "script-loguploader-main.xml" , CWD, "default", image=imagefile, text=message)
            qr.doModal()
            del qr
            xbmcvfs.delete(imagefile)
        else:
            dialog = xbmcgui.Dialog()
            confirm = dialog.ok(ADDONNAME, message)
web.py 文件源码 项目:ssland 作者: laobubu 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def admin_user_add():
    u = user.User()
    u.username, u.salted_password, u.sskey = [request.forms.get(n) for n in ('username', 'password', 'sskey')]
    u.create()
    u.write()
    return { "id": u.id }
wxbot.py 文件源码 项目:pythonPractice 作者: Bestfeel 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def gen_qr_code(self, qr_file_path):
        string = 'https://login.weixin.qq.com/l/' + self.uuid
        qr = pyqrcode.create(string)
        if self.conf['qr'] == 'png':
            qr.png(qr_file_path, scale=8)
            show_image(qr_file_path)
            # img = Image.open(qr_file_path)
            # img.show()
        elif self.conf['qr'] == 'tty':
            print(qr.terminal(quiet_zone=1))
app.py 文件源码 项目:besserberg 作者: Vnet-as 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def postprocess_pdf(input_pdf, qr_data, qr_x=545, qr_y=20, version=None):
    """ PDF post-processor. Append QR code on each PDF page.

    :param input_pdf: PDF byte content
    :param qr_data: QR code data
    :param qr_x: X possition of QR image
    :param qr_y: Y possition of QR image
    """

    qr = pyqrcode.create(qr_data, version=version)

    eps = StringIO()
    qr.eps(eps)
    eps.seek(0)

    qr_pdf = BytesIO()

    qr_img = Image(file=BytesIO(bytes(eps.read(), 'utf-8')))
    qr_img.format = 'pdf'
    qr_img.save(qr_pdf)

    qr_page = PdfFileReader(qr_pdf).getPage(0)

    output_writer = PdfFileWriter()
    output_pdf = BytesIO()

    for page in PdfFileReader(BytesIO(input_pdf)).pages:
        page.mergeTranslatedPage(qr_page, qr_x, qr_y)
        output_writer.addPage(page)

    output_writer.write(output_pdf)
    output_pdf.seek(0)

    return output_pdf.read()
commodity.py 文件源码 项目:tubuy 作者: SolubleCode 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def save(self, **kwargs):
        """overrides the save method for the model
        """
        request = pyqrcode.create(
            '{0}.{1}'.format(str(self.uuid), self.price),
            version=10
            )
        encoded_request = request.png_as_base64_str()
        image = Image.open(
            BytesIO(base64.b64decode(encoded_request.encode()))
            )
        filename = '{0}.{1}'.format(
            str(time.time())[:10],
            (image.format).lower()
        )
        memory_image = BytesIO()
        image.save(memory_image, format=image.format)
        qr_file = InMemoryUploadedFile(
            memory_image,
            None,
            filename,
            'image/png',
            memory_image.tell,
            None
        )
        self.commodity_qr.save(
            filename,
            qr_file,
            save=False,
        )
        super(Commodity, self).save(**kwargs)
CollectorURLScheme.py 文件源码 项目:collector-integration 作者: Esri 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def returnQRCodeText(self, validURL):
        objectQRCode = pyqrcode.create(validURL)
        return objectQRCode.text()
CollectorURLScheme.py 文件源码 项目:collector-integration 作者: Esri 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def saveQRCodeSVG(self, validURL, filename, imageDirectory=None):
        fullfilename = imageDirectory + filename if imageDirectory is not None else filename
        objectQRCode = pyqrcode.create(validURL)
        objectQRCode.svg(fullfilename + ".svg", scale=4)
        # in-memory stream is also supported
        buffer = io.BytesIO()
        objectQRCode.svg(buffer)
        # do whatever you want with buffer.getvalue()
        print(list(buffer.getvalue()))
CollectorURLScheme.py 文件源码 项目:collector-integration 作者: Esri 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def saveQRCodePNG(self, validURL, filename, imageDirectory=None):
        fullfilename = imageDirectory + filename if imageDirectory is not None else filename
        objectQRCode = pyqrcode.create(validURL)
        with open(fullfilename + ".png", 'wb') as fstream:
            objectQRCode.png(fstream, scale=5)
        # same as above
        objectQRCode.png(fullfilename + ".png", scale=5)
        # in-memory stream is also supported
        buffer = io.BytesIO()
        objectQRCode.png(buffer)
        # do whatever you want with buffer.getvalue()
        print(list(buffer.getvalue()))
wxbot.py 文件源码 项目:paperweekly_forum 作者: wwj718 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def gen_qr_code(self, qr_file_path):
        string = 'https://login.weixin.qq.com/l/' + self.uuid
        qr = pyqrcode.create(string)
        if self.conf['qr'] == 'png':
            qr.png(qr_file_path, scale=8)
            show_image(qr_file_path)
            # img = Image.open(qr_file_path)
            # img.show()
        elif self.conf['qr'] == 'tty':
            print(qr.terminal(quiet_zone=1))
wechat.py 文件源码 项目:WeChatBot 作者: laucyun 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def gen_qr_code(self, qr_file_path):
        string = 'https://login.weixin.qq.com/l/' + self.uuid
        qr = pyqrcode.create(string)
        if self.conf['qr'] == 'png':
            qr.png(qr_file_path, scale=8)
            show_image(qr_file_path)
        elif self.conf['qr'] == 'tty':
            ret = qr.terminal(quiet_zone=1)
            print ret
alimama.py 文件源码 项目:wx_taobao_fanli 作者: xsren 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def show_qr_image(self):
        self.logger.debug('begin to show qr image')
        url = 'https://qrlogin.taobao.com/qrcodelogin/generateQRCode4Login.do?from=alimama&_ksTS=%s_30&callback=jsonp31' % int(
            time.time() * 1000)

        # get qr image
        headers = {
            'method': 'GET',
            'authority': 'qrlogin.taobao.com',
            'scheme': 'https',
            'path': '/qrcodelogin/generateQRCode4Login.do?%s' % url.split('generateQRCode4Login.do?')[-1],
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
            'accept': '*/*',
            'referer': 'https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&from=alimama&redirectURL=http%3A%2F%2Flogin.taobao.com%2Fmember%2Ftaobaoke%2Flogin.htm%3Fis_login%3d1&full_redirect=true&disableQuickLogin=true',
            'accept-encoding': 'gzip, deflate, sdch, br',
            'accept-language': 'zh-CN,zh;q=0.8',
        }

        res = self.get_url(url, headers=headers)
        rj = json.loads(res.text.replace('(function(){jsonp31(', '').replace(');})();', ''))
        lg_token = rj['lgToken']
        url = 'https:%s' % rj['url']

        headers = {
            'method': 'GET',
            'authority': 'img.alicdn.com',
            'scheme': 'https',
            'path': '/tfscom/%s' % url.split('tfscom/')[-1],
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
            'accept': 'image/webp,image/*,*/*;q=0.8',
            'referer': 'https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&from=alimama&redirectURL=http%3A%2F%2Flogin.taobao.com%2Fmember%2Ftaobaoke%2Flogin.htm%3Fis_login%3d1&full_redirect=true&disableQuickLogin=true',
            'accept-encoding': 'gzip, deflate, sdch, br',
            'accept-language': 'zh,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4,zh-TW;q=0.2',
        }
        res = self.get_url(url, headers=headers)
        qrimg = BytesIO(res.content)

        sysstr = platform.system()
        if (sysstr == "Windows"):
            # windows?????????????
            img = Image.open(qrimg)
            img.show()
        elif (sysstr == "Linux") or (sysstr == "Darwin"):
            # ??url
            import zbarlight
            img = Image.open(qrimg)
            codes = zbarlight.scan_codes('qrcode', img)
            qr_url = codes[0]
            # ??pyqrcode????????linux????
            pyqrcode_url = pyqrcode.create(qr_url)
            print (pyqrcode_url.terminal())

        self.logger.debug(u"??????????")
        return lg_token

    # do login


问题


面经


文章

微信
公众号

扫码关注公众号