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
""" | |
Install dependencies using: | |
pip3 install Pillow, requests, lxml, cssselect | |
Edit your product ASIN IDs | |
Enter API KEY from scraperapi.com | |
""" | |
from io import BytesIO | |
import requests | |
from PIL import Image, UnidentifiedImageError |
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
""" | |
Generic pagination reusable at view level. | |
Paging middleware needs installing in the settings: | |
MIDDLEWARE = ( | |
... almost at the end... | |
'paging.paging_middleware', | |
Use in a view like so: |
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
"""Mobile phone detection middleware for Django""" | |
from django.utils.cache import patch_vary_headers | |
class MobileMiddleware: | |
def __init__(self, get_response): | |
self.get_response = get_response | |
def is_mobile(self, ua): | |
ua = ua.lower() |
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
# Setup of GIS libs from source for *NIX (older OS X) | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Sometimes package manager can't do | |
# e.g. Homebrew is broken for older OS X even High Sierra, so this is handy | |
# | |
# Warning: brew uninstalling your older but working brew packages on older OS X | |
# can get you in a situation where you won't be able to brew install them again!! | |
# | |
# https://docs.djangoproject.com/en/3.2/ref/contrib/gis/install/geolibs/ |
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
""" Create acronyms for names following rules | |
test using: python acronym_maker.py -v | |
""" | |
def acronym_maker(s): | |
""" | |
Make up 2 and 3 letter acronyms for given string | |
WIP: The following tests are not passing | |
2-letter short, 3-letter short, full name |
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
""" Extract dates from HTML | |
test using: python date_extract.py -v | |
""" | |
import calendar | |
import re | |
from datetime import date | |
from django.template.defaultfilters import striptags |
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
{% if debug %} | |
<div class="sql_debug"> | |
<div class="showhide"> | |
{{ sql_queries|length }} quer{{ sql_queries|pluralize:"y,ies" }} | |
{% ifnotequal sql_queries|length 0 %} | |
(<a href="#" onclick="var s=document.getElementById('queries').style;s.display=s.display=='none'?'':'none';this.innerHTML=this.innerHTML=='show'?'hide':'show';">show</a>) | |
{% endifnotequal %} | |
</div> | |
<div id="queries" style="display:none"> | |
{% for query in sql_queries %} |