This was tested on:
- Ubuntu 14.04 x64
- Ubuntu 16.04 x64
import logging | |
import time | |
from celery import shared_task as orig_shared_task | |
def timeit(func): | |
"""A decorator used to log the function execution time.""" | |
logger = logging.getLogger('tasks') |
/* Useful celery config. | |
app = Celery('tasks', | |
broker='redis://localhost:6379', | |
backend='redis://localhost:6379') | |
app.conf.update( | |
CELERY_TASK_RESULT_EXPIRES=3600, | |
CELERY_QUEUES=( | |
Queue('default', routing_key='tasks.#'), |
# Built-in imports. | |
from sys import argv | |
from os.path import join as join_path | |
# Third party imports. | |
from pandas import read_csv | |
def get_row_count(src_filepath): | |
with open(src_filepath, 'r') as f: |
from re import match | |
from urllib.parse import urlparse | |
from urllib.parse import ParseResult | |
def get_parsed_url(url): | |
p = urlparse(url, 'http') | |
netloc = p.netloc or p.path | |
path = p.path if p.netloc else '' | |
if not netloc.startswith('www.'): | |
netloc = 'www.' + netloc |
# from: https://github.com/dpkp/kafka-python/blob/master/example.py | |
import threading, logging, time | |
import multiprocessing | |
from kafka import KafkaConsumer, KafkaProducer | |
class Producer(threading.Thread): | |
def __init__(self): |
import sys, os, django | |
sys.path.append("/path/to/store") #here store is root folder(means parent). | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "store.settings") | |
django.setup() | |
from store_app.models import MyModel |
# -*- coding: utf-8 -*- | |
"""Example Google style docstrings. | |
This module demonstrates documentation as specified by the `Google Python | |
Style Guide`_. Docstrings may extend over multiple lines. Sections are created | |
with a section header and a colon followed by a block of indented text. | |
Example: | |
Examples can be given using either the ``Example`` or ``Examples`` | |
sections. Sections support any reStructuredText formatting, including |
In penance for cracking stupid jokes on Twitter, here's my Emacs cheat sheet. Emacs has a steep learning curve, so I've tried to order them by importance so you could learn them in stages.
One overall rule of thumb: pay attention to the minibuffer (the line at the bottom of the editor). It will often guide you through a process, and also gives you hints about what state you're in, such as the middle of a multi-chord sequence.
The other rule of thumb: when in doubt, C-g it out.
You simply can't get by without having these at your fingertips.
''' | |
This is an example of how to send data to Slack webhooks in Python with the | |
requests module. | |
Detailed documentation of Slack Incoming Webhooks: | |
https://api.slack.com/incoming-webhooks | |
''' | |
import json | |
import requests |