Exemple #1
0
    def __init__(self,
                 name,
                 category=None,
                 url=None,
                 username=None,
                 defaultExtraction=True):

        self.name = name
        self.category = category
        self.url = url
        self.username = username
        self.qrcode = None
        self.images = []
        self.imagesPath = os.sep.join([getResultsPath(), self.name])

        if self.username != None:
            self.imagesPath = os.sep.join([self.imagesPath, self.username])

        if not os.path.exists(self.imagesPath):
            os.makedirs(self.imagesPath)

        currentTries = 0
        maxTries = 3

        if url != None:

            qrSideSize = 75
            self.qrcode = Photo(name="qrcode",
                                path=self.imagesPath,
                                width=qrSideSize,
                                height=qrSideSize,
                                protocol="png")

            while (not self.qrcode.isDownloaded) and (currentTries < maxTries):

                if not os.path.exists(self.qrcode.path):
                    os.makedirs(self.qrcode.path)

                chart = pygooglechart.QRChart(qrSideSize, qrSideSize)
                chart.add_data(self.url)
                chart.set_ec('H', 0)

                try:
                    chart.download(self.qrcode.fullPath)
                except:
                    time.sleep(1)

                currentTries += 1

                if isFile(self.qrcode.fullPath):
                    self.qrcode.isDownloaded = True

            if defaultExtraction:
                threading.Thread(name="Website",
                                 target=self.extractData).start()
Exemple #2
0
 def test_validate_shift_jis(self):
     # XXX: It looks like PyQrcodec doesn't do shift_jis?
     text = unicode('こんにちは世界', 'utf-8').encode('shift_jis')
     chart = gc.QRChart(100, 100)
     chart.add_data(text)
     chart.set_ec('H', 0)
     chart.set_encoding('Shift_JIS')
     self.assertChartURL(chart.get_url(), \
         '?cht=qr&chs=100x100&chl=%82%B1%82%F1%82%C9' \
         '%82%BF%82%CD%90%A2%8AE&choe=Shift_JIS&chld=H|0')
     chart.download(self.temp_image)
Exemple #3
0
 def test_validate_utf8(self):
     text = 'こんにちは世界'  # Hello world in Japanese UTF-8
     chart = gc.QRChart(100, 100)
     chart.add_data(text)
     chart.set_ec('H', 0)
     self.assertQRImage(chart, text)
Exemple #4
0
 def test_validate_image(self):
     text = 'Hello World'
     chart = gc.QRChart(100, 100)
     chart.add_data(text)
     chart.set_ec('H', 0)  # PyQrcodec seems to only work on higher EC
     self.assertQRImage(chart, text)
Exemple #5
0
 def test_no_data(self):
     chart = gc.QRChart(100, 100)
     self.assertRaises(gc.NoDataGivenException, chart.get_url)
Exemple #6
0
 def test_encoding(self):
     chart = gc.QRChart(100, 100)
     chart.add_data('Hello World')
     self.assertChartURL(chart.get_url(), \
         '?cht=qr&chs=100x100&chl=Hello%20World')
Exemple #7
0
 def test_simple(self):
     text = 'Hello World'
     chart = gc.QRChart(100, 150)
     chart.add_data(text)
     self.assertChartURL(chart.get_url(), \
         '?cht=qr&chs=100x150&chl=Hello%20World')