Final touches before deployment, celery installed
This commit is contained in:
1 parent
827c6738a8
commit
977a3eeb82
1210 files changed
+133115
-74
No files matched your search
@@ -0,0 +1,7 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
# This will make sure the app is always imported when
|
||||
# Django starts so that shared_task will use this app.
|
||||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,3 +4,6 @@ from django.apps import AppConfig
|
||||
class LottopyConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'lottopy'
|
||||
def ready(self):
|
||||
# Initialize celery
|
||||
import lottopy.celery
|
||||
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lottopy.settings')
|
||||
|
||||
app = Celery('lottopy')
|
||||
|
||||
# Using a string here means the worker doesn't have to serialize
|
||||
# the configuration object to child processes.
|
||||
# - namespace='CELERY' means all celery-related configuration keys
|
||||
# should have a `CELERY_` prefix.
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
# Load task modules from all registered Django apps.
|
||||
app.autodiscover_tasks()
|
||||
|
||||
|
||||
#@app.task(bind=True)
|
||||
#def debug_task(self):
|
||||
# print(f'Request: {self.request!r}')
|
||||
@@ -1,2 +1,2 @@
|
||||
Winning_Numbers,Chance
|
||||
14-18-22-23-5-9,347/177100
|
||||
14-18-2-22-5-9,49/25300
|
||||
|
Binary file not shown.
@@ -1,2 +1,2 @@
|
||||
Winning_Numbers,Chance
|
||||
0-3-6,17/5000
|
||||
0-8-9,2/625
|
||||
|
@@ -1,2 +1,2 @@
|
||||
Winning_Numbers,Chance
|
||||
3-5-6-8,267/5000
|
||||
3-5-7-8,67/1250
|
||||
|
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
||||
Winning_Numbers,SB,Chance
|
||||
1-10-32-49-8,[3],1/270725
|
||||
1-10-32-46-8,[9],1/265200
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
||||
Winning_Numbers,MB,Chance
|
||||
17-26-40-52-7,[24],1/4034338
|
||||
17-26-40-52-7,[24],38/151287675
|
||||
|
@@ -1,2 +1,2 @@
|
||||
Winning_Numbers,PB,Chance
|
||||
21-33-39-59-63,[17],16/48700223
|
||||
21-39-59-61-63,[17],3/8854586
|
||||
|
@@ -1,3 +1,16 @@
|
||||
from django.db import models
|
||||
import os, csv
|
||||
|
||||
# Create your models here.
|
||||
class Lotto():
|
||||
module_dir = os.path.dirname(__file__)
|
||||
names = list(["pb", "mm", "la", "d3", "d4", "c25"])
|
||||
files = list()
|
||||
for i in names:
|
||||
files.append(os.path.join(module_dir,"lottopy_web_edition",i+"_ans.csv"))
|
||||
files = [i for i in files if os.path.isfile(i)]
|
||||
|
||||
def get_ans(f):
|
||||
ans = csv.DictReader(open(f), delimiter=',')
|
||||
fmt = [str(k)[1:-1].replace("'"," ").replace("_"," ") for k in ans]
|
||||
return str(fmt).replace(",","\n").replace("[","").replace("]","").replace("'","")
|
||||
@@ -0,0 +1,14 @@
|
||||
from django.contrib import sitemaps
|
||||
from django.urls import reverse, path
|
||||
from .views import home, about, robots_txt
|
||||
|
||||
class StaticViewSitemap(sitemaps.Sitemap):
|
||||
protocol = 'http'
|
||||
priority=.5,
|
||||
changefreq='weekly'
|
||||
|
||||
def items(self):
|
||||
return ['home', 'about', 'robots_txt']
|
||||
|
||||
def location(self, item):
|
||||
return reverse(item)
|
||||
@@ -0,0 +1,30 @@
|
||||
import os, csv
|
||||
from celery import shared_task
|
||||
|
||||
@shared_task()
|
||||
def secret():
|
||||
string = "If you can see this, fuck off"
|
||||
return string
|
||||
|
||||
module_dir = os.path.dirname(__file__)
|
||||
|
||||
def get_ans(f):
|
||||
ans = csv.DictReader(open(f), delimiter=',')
|
||||
fmt = [str(k)[1:-1].replace("'"," ").replace("_"," ") for k in ans]
|
||||
return str(fmt).replace(",","\n").replace("[","").replace("]","").replace("'","")
|
||||
|
||||
all_nums = []
|
||||
|
||||
@shared_task()
|
||||
class data_task():
|
||||
def __init__():
|
||||
pb_file_path = os.path.join(module_dir,'lottopy_web_edition/pb_ans.csv')
|
||||
mm_file_path = os.path.join(module_dir,'lottopy_web_edition/mm_ans.csv')
|
||||
la_file_path = os.path.join(module_dir,'lottopy_web_edition/la_ans.csv')
|
||||
d3_file_path = os.path.join(module_dir,'lottopy_web_edition/d3_ans.csv')
|
||||
d4_file_path = os.path.join(module_dir,'lottopy_web_edition/d4_ans.csv')
|
||||
c25_file_path = os.path.join(module_dir,'lottopy_web_edition/c25_ans.csv')
|
||||
data_task.all_nums.append(pb_file_path, mm_file_path, la_file_path, d3_file_path, d4_file_path, c25_file_path)
|
||||
|
||||
return get_ans(all_nums)
|
||||
#return pbnumbers, mmnumbers, lanumbers, d3numbers, d4numbers, c25numbers
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
from lottopy import views
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
@@ -1,84 +1,52 @@
|
||||
# Create your views here.
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.http import require_GET
|
||||
from django.shortcuts import render
|
||||
from django.conf import settings
|
||||
from django.core.cache.backends.base import DEFAULT_TIMEOUT
|
||||
from django.views.decorators.cache import cache_page
|
||||
import os
|
||||
import csv
|
||||
from .models import Lotto
|
||||
|
||||
#f = "~/projects/django_lottopy/lottopy_site/lottopy/lottopy_web_edititon/pb_ans.csv"
|
||||
|
||||
# MAKE SURE TO START REDIS BEFORE SITE LOADS
|
||||
CACHE_TTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT)
|
||||
|
||||
@cache_page(CACHE_TTL)
|
||||
def base(request):
|
||||
return render(request, 'lottopy/base.html',
|
||||
{'nbar': 'home'})
|
||||
|
||||
CACHE_TTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT)
|
||||
@cache_page(CACHE_TTL)
|
||||
def home(request):
|
||||
# Powerball
|
||||
module_dir = os.path.dirname(__file__)
|
||||
pb_file_path = os.path.join(module_dir,'lottopy_web_edition/pb_ans.csv')
|
||||
pb = csv.DictReader(open(pb_file_path), delimiter=',')
|
||||
pb_numbers = {}
|
||||
for x in pb:
|
||||
pbnumbers = str(x)[1:-1].replace("'"," ").replace(",","\n").replace("_"," ")
|
||||
pbnumbers.capitalize()
|
||||
def home(request):
|
||||
|
||||
# MegaMil
|
||||
mm_file_path = os.path.join(module_dir,'lottopy_web_edition/mm_ans.csv')
|
||||
mm = csv.DictReader(open(mm_file_path), delimiter=',')
|
||||
mmnumbers = {}
|
||||
for y in mm:
|
||||
mmnumbers = str(y)[1:-1].replace("'"," ").replace(",","\n").replace("_"," ")
|
||||
|
||||
# Lotto America
|
||||
la_file_path = os.path.join(module_dir,'lottopy_web_edition/la_ans.csv')
|
||||
la = csv.DictReader(open(la_file_path), delimiter=',')
|
||||
lanumbers = {}
|
||||
for z in la:
|
||||
lanumbers = str(z)[1:-1].replace("'"," ").replace(",","\n").replace("_"," ")
|
||||
|
||||
# Daily3
|
||||
d3_file_path = os.path.join(module_dir,'lottopy_web_edition/d3_ans.csv')
|
||||
d3 = csv.DictReader(open(d3_file_path), delimiter=',')
|
||||
d3numbers = {}
|
||||
for a in d3:
|
||||
d3numbers = str(a)[1:-1].replace("'"," ").replace('"', " ").replace(",","\n").replace("_"," ")
|
||||
|
||||
# Daily4
|
||||
d4_file_path = os.path.join(module_dir,'lottopy_web_edition/d4_ans.csv')
|
||||
d4 = csv.DictReader(open(d4_file_path), delimiter=',')
|
||||
d4numbers = {}
|
||||
for b in d4:
|
||||
d4numbers = str(b)[1:-1].replace("'"," ").replace('"', " ").replace(",","\n").replace("_"," ")
|
||||
|
||||
# Cash25
|
||||
c25_file_path = os.path.join(module_dir,'lottopy_web_edition/c25_ans.csv')
|
||||
c25 = csv.DictReader(open(c25_file_path), delimiter=',')
|
||||
c25numbers = {}
|
||||
for c in c25:
|
||||
c25numbers = str(c)[1:-1].replace("'"," ").replace('"', " ").replace(",","\n").replace("_"," ")
|
||||
|
||||
#Sanitizer (WIP)
|
||||
#for key, value in pbnumbers.items():
|
||||
# pbnumbers = str(key)+":"+value
|
||||
|
||||
|
||||
context = {
|
||||
'nbar': 'home',
|
||||
'pbnumbers': pbnumbers,
|
||||
'mmnumbers': mmnumbers,
|
||||
'lanumbers': lanumbers,
|
||||
'd3numbers': d3numbers,
|
||||
'd4numbers': d4numbers,
|
||||
'c25numbers': c25numbers,
|
||||
'active': 'active'
|
||||
'pbnumbers': Lotto.get_ans(Lotto.files[0]),
|
||||
'mmnumbers': Lotto.get_ans(Lotto.files[1]),
|
||||
'lanumbers': Lotto.get_ans(Lotto.files[2]),
|
||||
'd3numbers': Lotto.get_ans(Lotto.files[3]),
|
||||
'd4numbers': Lotto.get_ans(Lotto.files[4]),
|
||||
'c25numbers': Lotto.get_ans(Lotto.files[5]),
|
||||
}
|
||||
|
||||
return render(request, 'lottopy/home.html', context)
|
||||
|
||||
@cache_page(CACHE_TTL)
|
||||
def about(request):
|
||||
return render(request, 'lottopy/about.html',
|
||||
{'nbar': 'about', 'title': 'About'})
|
||||
|
||||
@cache_page(CACHE_TTL)
|
||||
@require_GET
|
||||
def robots_txt(require_GET):
|
||||
lines = [
|
||||
"User-Agent: *",
|
||||
"Disallow: /private/",
|
||||
"Disallow: /junk/",
|
||||
]
|
||||
return HttpResponse("\n".join(lines), content_type="text/plain")
|
||||
|
||||
def sitemap(request):
|
||||
return render(request,sitemaps,section=None,template_name='sitemap.xml',content_type='application/xml',)
|
||||
|
||||
Reference in new issue
Block a user