forked from Anugrah2002/botyoutube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
90 lines (65 loc) · 2.8 KB
/
views.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
from processArticle import *
from makeVideos import *
from wsgiref.util import FileWrapper
from uploadToYT import *
import os
from django.conf import settings
import shutil
from gtts import gTTS
import random
import settings
import requests, json, datetime
from uploadfiletoheroku import *
def checktime():
# fetchdata=requests.get('http:/ytserver.eu-gb.cf.appdomain.cloud/entertainx/')
fetchdata=requests.get('https://ytserver.eu-gb.cf.appdomain.cloud/entertainx/')
data=fetchdata.json()
# print(data['nextrandom'])
nextran= datetime.datetime.strptime(data['nextrandom'],"%Y-%m-%dT%H:%M:%SZ")
print(nextran)
# print(nextran)
# print(type(nextran))
# print(datetime.now)
datime=datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
print(datime)
dateee=datetime.datetime.strptime(datime,"%Y-%m-%d %H:%M:%S")
if nextran < dateee:
print("We will post video")
requestVideo()
else:
print("We will wait for minutes since it is time error")
def requestVideo():
try:
r=requests.get('https://ytserver.eu-gb.cf.appdomain.cloud/gettitle/')
print(r)
title=(r.json()['title'])
YTtitle=(r.json()['Ytitle'])
content=(r.json()['content'])
summary=(r.json()['summary'])
if title == 0 or title is None or content is None or content == '':
print("Content or title is either blank or incorrect")
exit()
# #Replacing space with hiphens to resolve filepath issue in linux
# if title is not None:
# title.replace(' ','-')
newYTtitle = YTtitle
# newYTtitle = newYTtitle.replace(' ','-')
p = makeVideo(newYTtitle+' hd',content)
if p =='GTTS ERR':
shutil.rmtree(os.path.join(settings.BASE_DIR, r"dataset"))
return HttpResponse('GTTS ERR')
os.chdir(os.path.join(settings.BASE_DIR,''))
credit = '''\nWe take DMCA very seriously. All the images are from Bing Images.Since all the contents are not moderated so If anyway we hurt anyone sentiment, send us a request with valid proof.
'''
keywords = ','.join(str(YTtitle).split())
print(YTtitle)
command = 'python ./bott/uploadToYT.py --file="'+str(p)+'" --title="'+YTtitle+'" --description="'+(summary+'\n'+credit)+'" --keywords="'+keywords+',hour news,news" --category="24" --privacyStatus="public" --noauth_local_webserver '
uploadvideotoheroku(p,YTtitle)
# os.system(command) #comment this to stop uploading to youtube
# shutil.rmtree(os.path.join(settings.BASE_DIR, r"dataset")) # comment this to stop removing the file from system
print('Success')
except Exception as e:
print('views function')
print(e)
checktime()