no more apache2

This commit is contained in:
Arthur 2025-02-25 18:24:29 +01:00
commit d8bd75003b
79 changed files with 52 additions and 27 deletions

View file

@ -0,0 +1,3 @@
from .articles_list import ArticleList
from .articles_detail import ArticleDetail
from .index import IndexView

View file

@ -0,0 +1,5 @@
from django.views.generic import DetailView
from blog.models import Article
class ArticleDetail(DetailView):
model = Article

View file

@ -0,0 +1,11 @@
from django.views.generic import ListView
from blog.models import Article
class ArticleList(ListView):
preview = False
def get_queryset(self):
status = 1
if self.preview:
status = 0
return Article.objects.filter(status=status)

View file

@ -0,0 +1,60 @@
from django.views.generic import View
from django.http.response import HttpResponse
import shutil
import requests
import json
def save_image(post):
res = requests.get(post['media'], stream = True)
file_name = "/var/www/sciodog.fr/blog/static/blog/posts/" + post['url'].split('/')[-1]
try:
if res.status_code == 200:
with open(file_name,'wb') as f:
shutil.copyfileobj(res.raw, f)
post['media'] = "https://sciodog.fr/static/blog/posts/" + post['url'].split('/')[-1]
except IsADirectoryError as e:
pass
class IndexView(View):
template_name = "blog/index.html"
def get(self, *args, **kwargs):
context = {}
access_token = 'EAAEiPRfMZCtsBO9WSI2FMTKXeZBOFXoZBtHBbtBVLeSJh4ZAqIZC9PasW0li3IbPsWXrsVYn1yxPnRmMP8ZCs0aPT64dRd9FHaw0px6C61YwbgZALgNLCYWqD7MeTZCIq09MGwz044B2FO2JiuLMl0r16tNzHwJN4fQ5puXJeL6TZAUvcgaoIOglU1OEN55cssvYZD'
params = {
'access_token': access_token
}
url = 'https://graph.facebook.com/v13.0/102786409210660/feed?fields=attachments,message,permalink_url&limit=10'
response = requests.get(url, params=params)
posts = []
if response.status_code == 200:
data = response.json()
for post in data['data']:
ok = True
temp = {}
if 'message' in post.keys():
temp['message'] = post['message']
else:
ok = False
if 'attachments' in post.keys():
try:
try:
temp['media'] = post['attachments']['data'][0]['media']['image']['src']
except:
temp['media'] = post['attachments']['data'][0]['media']['image']['src']
except:
ok = False
else:
ok = False
if 'permalink_url' in post.keys():
temp['url'] = post['permalink_url']
else:
ok = False
if ok:
posts.append(temp)
save_image(temp)
else:
return HttpResponse(status=300, content=response.text)
return HttpResponse(status=200, content=json.dumps(posts))