Merge pull request 'testing' (#22) from testing into main
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4m10s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4m10s
Reviewed-on: #22
This commit was merged in pull request #22.
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
import requests
|
import requests
|
||||||
import xmltodict
|
import xmltodict
|
||||||
from urllib import request as urlrequest
|
from urllib import request as urlrequest
|
||||||
|
import tempfile
|
||||||
|
#Django import
|
||||||
from apps.telegram_communication.utils import telegramUtils
|
from apps.telegram_communication.utils import telegramUtils
|
||||||
from .models import podcastData
|
from .models import podcastData
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proxy_url = 'http://gluetun-svc.gluetun.svc:8888'
|
proxy_url = 'http://gluetun-svc.gluetun.svc:8888'
|
||||||
proxy = urlrequest.ProxyHandler({
|
proxy = urlrequest.ProxyHandler({
|
||||||
'http': proxy_url,
|
'http': proxy_url,
|
||||||
@@ -47,7 +51,9 @@ def download_news_mp3(url_mp3, filename):
|
|||||||
|
|
||||||
print("Downloading : " + filename +" -- " + url_mp3)
|
print("Downloading : " + filename +" -- " + url_mp3)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
urlrequest.urlretrieve(url_mp3, filename)
|
urlrequest.urlretrieve(url_mp3, filename)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("Can't download " + filename +" -- " + url_mp3 + " == Cancelling")
|
print("Can't download " + filename +" -- " + url_mp3 + " == Cancelling")
|
||||||
return 0
|
return 0
|
||||||
@@ -71,8 +77,13 @@ def podcasts():
|
|||||||
|
|
||||||
today_podcast = rss_to_dict(url)
|
today_podcast = rss_to_dict(url)
|
||||||
print(today_podcast)
|
print(today_podcast)
|
||||||
file= pretty_filename(today_podcast[1],'mp3')
|
pretty_file_name = pretty_filename(today_podcast[1],'mp3')
|
||||||
download_news_mp3(today_podcast[2],file)
|
|
||||||
telegram.send_document(file,str(today_podcast[0])+" "+str(today_podcast[1]))
|
temp = tempfile.TemporaryDirectory()
|
||||||
|
temp_path = temp.name.replace("\\", "/")
|
||||||
|
file_path = temp_path+"/"+pretty_file_name
|
||||||
|
download_news_mp3(today_podcast[2],file_path)
|
||||||
|
print(file_path)
|
||||||
|
telegram.send_document(file_path,str(today_podcast[0])+" "+str(today_podcast[1]))
|
||||||
|
|
||||||
#main()
|
#main()
|
||||||
|
|||||||
@@ -1,8 +1,26 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from import_export.admin import ImportExportModelAdmin
|
from import_export.admin import ImportExportModelAdmin
|
||||||
from .models import TelegramData
|
from .models import TelegramData
|
||||||
|
from .utils import telegramUtils
|
||||||
|
|
||||||
|
@admin.action(description="Clear all expired messages")
|
||||||
|
def messages_cleaning(modeladmin, request, queryset):
|
||||||
|
telegram = telegramUtils()
|
||||||
|
telegram.clear_expired_messages()
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
@admin.register(TelegramData)
|
@admin.register(TelegramData)
|
||||||
class JobAdmin(ImportExportModelAdmin):
|
class JobAdmin(ImportExportModelAdmin):
|
||||||
list_display = ('message_id','chat_id','description','creation_date','expiration_date')
|
list_display = ('message_id','chat_id','description','creation_date','expiration_date')
|
||||||
|
actions = [messages_cleaning]
|
||||||
|
|
||||||
|
def delete_queryset(self, request, queryset):
|
||||||
|
"""Given a queryset, delete it from the database."""
|
||||||
|
print("here")
|
||||||
|
telegram = telegramUtils()
|
||||||
|
list_of_message_id = list(queryset.all().values_list('message_id',flat=True))
|
||||||
|
telegram.delete_message(list_of_message_id)
|
||||||
|
#no queryset.delete() because it is specified in delete_message function already
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user