-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtwitter_releases_tweets.py
executable file
·66 lines (57 loc) · 2.21 KB
/
twitter_releases_tweets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#==============================================================================
# DEPRECATED this moved into class functions
# the cronjob is done via notifications_cronjob.py
#
# This script notifies about released subtitles and about subtitles which need
# review
# It checks the "notify_subtitle_released" flag and if the syn_to_ftp flag is on false again to
# be sure the file is already released
#
# Currently the YT-Flags are ignored!
# Only updates on media are tweeted
#==============================================================================
import os
import sys
import requests
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "subtitleStatus.settings")
import django
django.setup()
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.core.exceptions import ObjectDoesNotExist
from www.models import Subtitle
import tweets
# Set all finished subtitles to "notify_subtitle_released"
"""
my_subtitles = Subtitle.objects.filter(complete = True)
for every in my_subtitles:
every.notify_subtitle_released = True
every.save()
print(my_subtitles.count())
"""
# Get all Subtitles which are already synced to the sync folder and still might need a notification
my_subtitles = Subtitle.objects.filter(notify_subtitle_released = True, needs_sync_to_sync_folder = False)
# Notify for every subtitle synced to sync folder if the file is already on the mirror
for s in my_subtitles:
link = "https://mirror.selfnet.de/c3subtitles/" + s.talk.event.subfolder_in_sync_folder + "/" + s.get_filename_srt()
try:
request = requests.head(link)
except:
continue
# Only notify if the file is on the mirror
if request.status_code == 200:
tweets.tweet_subtitles_update_mirror(s.id)
s.refresh_from_db()
s.notify_subtitle_released = False
s.save()
else:
continue
# Notify which talk needs an Review
my_subtitles = Subtitle.objects.filter(state_id = 7, notify_subtitle_ready_for_quality_control = True)
for s in my_subtitles:
tweets.tweet_subtitle_needs_quality_control(s.id)
s.refresh_from_db()
s.notify_subtitle_ready_for_quality_control = False
s.save()