This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir qr_card_generator | |
cd qr_card_generator | |
virtualenv -p /le/chemin/de/python3 venv # Init du virtualenv en spécifiant le chemin de Python3 (sur mon système, Python 2.7 est par défaut) | |
source venv/bin/activate # Activation du virtualenv | |
pip install qrcode pillow # Installation des deux libs nécessaires | |
touch card-generator.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_UUIDs(qty): | |
''' Return a list of `qty` UUIDs ''' | |
return [str(uuid4()) for _ in range(qty)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_UUIDs(qty): | |
''' Return a list of `qty` UUIDs ''' | |
return [str(uuid4()) for _ in range(qty)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def data_to_qrcode(data): | |
''' Return a qrcode image from data ''' | |
qrc = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_Q, | |
box_size=8, | |
border=0) | |
qrc.add_data(data) | |
qrc.make(fit=True) | |
img = qrc.make_image() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for cpt, elt_id in enumerate(input_ids): | |
# Copy the background to the new image, then draw it | |
new_bg = copy(bg_image) | |
draw = ImageDraw.Draw(new_bg) | |
# Generate a QR code as image | |
qr_image = data_to_qrcode(elt_id) | |
qr_x, qr_y = qr_image.size # Get width/height of QR code image |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def page_to_index(page_num): | |
''' Transforms page number into start index to be written in Yelp URL ''' | |
return (page_num - 1)*10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_yelp_url(page, c): | |
''' Builds Yelp URL for the given page and cflt to be parsed according to | |
config variables ''' | |
url = "http://www.yelp.fr/search?&start={0}".format(page_to_index(page)) | |
if CITY: url += "&find_loc={0}".format(CITY) | |
url += "&cflt={0}".format(c) # We assume that CFLTS list is not empty | |
if PARIS_DISTRICTS: url += "&l=p:FR-75:Paris::{0}".format( | |
build_arglist(PARIS_DISTRICTS)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_results = soup.find_all('div', attrs={"class":u"search-result"}): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for sr in search_results: | |
shop_name = sr.find('a', attrs={"class":u"biz-name"}).get_text() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_advertisement(search_result): | |
''' Return True is the search result is an add ''' | |
if search_result.find('span', attrs={"class":u"yloca-tip"}): | |
return True | |
return False |
OlderNewer