Skip to content

Instantly share code, notes, and snippets.

View trAve3113r's full-sized avatar

Arthur Mwai trAve3113r

  • East Africa,Kenya
View GitHub Profile
import pandas pd
import numpy as np
from pandas import *
# create a dataframe with the last candles bars being an inside_bar pattern
# bullish_candle: close > open
# bearish_candles: open > close
# mother_bar :: open = 70.123 , high =102.634 ,low = 80.021 , close = 97.653
# create this in etc/supervisor/conf.d/task_manager.conf
[program:task_manager]
command=bash -c "echo starting main.huey && sleep $(( $RANDOM / 2500 + 4)) && exec huey_consumer.py main.huey"
environment=PYTHONPATH=%(here)s/..
numprocs=1
process_name=%(program_name)s-%(process_num)d
stopwaitsecs=5
stdout_logfile=%(here)s/huey.log
def my_wrapper(func):
try:
return func
except MyException as e:
return "My traceback"
def my_task(*args,**kwargs):
yada = x + 1
# -------------------------------- #
# the main advanatages of celery : #
# -------------------------------- #
# queueing,
# 0. http://python-rq.org/
# queueing is for invoking a function asynchronously
# retries (the most important feature)::
# 0. https://pypi.org/project/backoff/ :: perfect solution
@trAve3113r
trAve3113r / cron_to_run_script.py
Last active August 18, 2021 09:46
Run python scripts in virtualenv using cron
# execute a python script in virtualenn using cron
# web links to solutions
# http://www.adminschoice.com/crontab-quick-reference
# https://www.unix.com/man-page/linux/5/crontab/
PATH="" # RUN 'echo PATH' as root
[email protected]
# setup e-mail first :: https://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/
# Toy solution :: not production-ready but food for thought
# https://jeffknupp.com/blog/2014/02/11/a-celerylike-python-task-queue-in-55-lines-of-code/
# This article shows how to daemonize a job using supervisord
# https://adamj.eu/tech/2014/08/16/time-to-move-on-from-cron/
# Below is the github repo link
# https://github.com/dbader/schedule
# --------------------------------------- #
from django_cron import CronJobBase, Schedule
class FetchData(CronJobBase):
#RUN_EVERY_MINS = 1
#RUN_EVERY_SECONDS = 30 :: non-existent feature
# maybe we should just write a simple django-mgt comd then daemonize it
RUN_AT_TIMES = trading_hours #list of hours
schedule = Schedule(run_every_mins=RUN_EVERY_MINS, run_at_times=RUN_AT_TIMES)
code = 'my_app.my_cron_job' # a unique code
; Create default config file -- solves the unix server error
; credits: https://stackoverflow.com/questions/20067116/supervisorctl-error-unix-var-run-supervisord-sock-refused-connection
echo_supervisord_conf > /etc/supervisord.conf
sudo supervisord -c /etc/supervisord.conf
sudo supervisorctl status
; Missing '/var/run/supervisor.sock' file?
touch var/run/supervisor.sock
chmod 777 var/run/supervisor.sock
service supervisor restart
https://docs.python.org/3/howto/pyporting.html
https://docs.python.org/3/whatsnew/index.html
https://stackoverflow.com/questions/43957004/upgrade-python-3-4-3-to-python-3-6-1-in-ubuntu-15-0464-bit
https://docs.python.org/3/library/venv.html
https://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3
# views
# https://django.readthedocs.io/en/2.1.x/topics/class-based-views/index.html
# https://django.readthedocs.io/en/2.1.x/ref/class-based-views/index.html
#urls.py
from django.urls import include,path, re_path
from django.views.generic import TemplateView
from . import views
urlpatterns = [