Instead of:
if s.startswith('http://') or s.startswith('https://'): ...
You can do:
if s.startswith(('http://', 'https://')): ...
#!/usr/bin/env python | |
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE | |
# Written by Nathan Hamiel (2010) | |
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler | |
from optparse import OptionParser | |
class RequestHandler(BaseHTTPRequestHandler): | |
def do_GET(self): |
from scrapy.xlib.pydispatch import dispatcher | |
from scrapy import signals | |
from scrapy.exceptions import DropItem | |
from scrapy.utils.serialize import ScrapyJSONEncoder | |
from carrot.connection import BrokerConnection | |
from carrot.messaging import Publisher | |
from twisted.internet.threads import deferToThread |
import math | |
import Image | |
import Levenshtein | |
class BWImageCompare(object): | |
"""Compares two images (b/w).""" | |
_pixel = 255 |
from celery.schedules import crontab | |
from flask.ext.celery import Celery | |
CELERYBEAT_SCHEDULE = { | |
# executes every night at 4:15 | |
'every-night': { | |
'task': 'user.checkaccounts', | |
'schedule': crontab(hour=4, minute=20) | |
} | |
} |
Instead of:
if s.startswith('http://') or s.startswith('https://'): ...
You can do:
if s.startswith(('http://', 'https://')): ...
#Retrive old website from Google Cache. Optimized with sleep time, and avoid 504 error (Google block Ip send many request). | |
#Programmer: Kien Nguyen - QTPros http://qtpros.info/kiennguyen | |
#change search_site and search_term to match your requirement | |
#Original: http://www.guyrutenberg.com/2008/10/02/retrieving-googles-cache-for-a-whole-website/ | |
#!/usr/bin/python | |
import urllib, urllib2 | |
import re | |
import socket |
<form method="post"> | |
{{ form.hidden_tag() }} | |
{{ form.example }} | |
<input type="submit"> | |
</form> |
The program below can take one or more plain text files as input. It works with python2 and python3.
Let's say we have two files that may contain email addresses:
foo bar
ok ideler.dennis@gmail.com sup
hey...user+123@example.com,wyd
hello world!
import email | |
def get_decoded_email_body(message_body): | |
""" Decode email body. | |
Detect character set if the header is not set. | |
We try to get text/plain, but if there is not one then fallback to text/html. | |
:param message_body: Raw 7-bit message body input e.g. from imaplib. Double encoded in quoted-printable and latin-1 |
git
discard all local changes/commits and pull from upstream
git reset --hard origin/master
git pull origin master