-
Notifications
You must be signed in to change notification settings - Fork 12
/
post.py
executable file
·151 lines (121 loc) · 3.85 KB
/
post.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import json
import telebot
from telebot import util
from datetime import date
from datetime import datetime
import json
from os import system
import os
keys = open('config.json',)
data = json.load(keys)
API_KEY = data['API_KEY']
BLOG_ID = data['BLOG_ID']
CHAT_ID = data['CHAT_ID']
keys.close()
bot = telebot.TeleBot(API_KEY)
part1 = '''
<html>
<head>
<style>
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap");
.card {
width: 350px;
height: 87px;
border-radius: 20px;
background-color: #fff;
padding: 10px 10px;
position: relative;
}
.main,
.copy-button {
display: flex;
justify-content: space-between;
padding: 0 10px;
align-items: center;
}
.copy-button {
margin: 12px 0 -5px 0;
height: 45px;
border-radius: 4px;
padding: 0 5px;
border: 1px solid #e1e1e1;
}
.copy-button input {
width: 55%;
height: 100%;
border: none;
outline: none;
font-size: 15px;
}
.copy-button button {
padding: 5px 20px;
background-color: #dc143c;
color: #fff;
border: 1px solid transparent;
}
</style>
</head>
<body>
<div class="separator" style="clear: both;"><a href="https://1.bp.blogspot.com/-f5NKdS1sCsc/YKd5kR-2E9I/AAAAAAAAABo/ykARrUdn750UobuBvmmVodmsfb78uubBgCLcBGAsYHQ/s300/udemy.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="168" data-original-width="300" src="https://1.bp.blogspot.com/-f5NKdS1sCsc/YKd5kR-2E9I/AAAAAAAAABo/ykARrUdn750UobuBvmmVodmsfb78uubBgCLcBGAsYHQ/s320/udemy.png"/></a></div>
<p>
<script>
let copybtn = document.querySelector(".copybtn");
function copyIt(i){
var x = document.getElementsByClassName("test")[i].id;
let copyInput = document.querySelector(`#${x}`);
copyInput.select();
document.execCommand("copy");
copybtn.textContent = "COPIED";
}
</script>
'''
part2 = '</body></html>'
##
def rem_code(str):
str_en = str.encode("ascii", "ignore")
str_de = str_en.decode()
return str_de
#print("started..")
file = open('courses.json', 'r')
a = json.loads(file.read())
file.close()
fn = str(date.today().strftime("%d%m")) + '-' + str(datetime.now().strftime("%H%M"))
file = open('./htmls/courses_{}.html'.format(fn), 'w')
courses = a['courses']
l = len(courses)
file.write(part1)
for i in range(l):
file.write("<h3>{}</h3>".format(rem_code(courses[i]['title'])))
file.write("<p><h6>{}</h6>".format(courses[i]['date']))
file.write('<div class="card"><div class="copy-button"><input class="test" id="'+str("ran{}".format(i))+'" type="text" readonly value="'+str(courses[i]['coupon'])+'"/><button onclick="copyIt('+str(i)+')" class="copybtn">COPY COUPON</button></div></div>')
file.write("<p><b>Enroll Now !</b> - <a href={} target='_blank'>{}</a>".format(courses[i]['enroll'], courses[i]['enroll']))
file.write("<br><hr><br>")
file.write(part2)
file.close()
#print("\nCompleted!")
try:
if BLOG_ID == '':
raise Exception("Add keys in config.json")
print("\n[+] Posting the Blog to blogger...")
system('easyblogger --blogid {} post -t "Free Udemy Courses - {}" -l "coupons,udemy" --publish -f ./htmls/courses_{}.html'.format(BLOG_ID, date.today().strftime("%d %b"), fn))
print("\n[+] Posted successfully!")
except:
print("\n[+] Add keys in config.json file !\n")
exit()
tel = ''
tel = tel + '*FREE UDEMY COURSES - {}*'.format(date.today().strftime("%d-%B"))
tel = tel + '\n\n'
print("\n[+] Sending to Telegram bot")
for i in range(l):
tel = tel+'*COURSE* : {}\n'.format(courses[i]['title'])
tel = tel+'*COUPON* : {}\n'.format(courses[i]['coupon'])
tel = tel+'*LINK* : http://bitly.com/free-course-coupons\n'
tel = tel+'\n'
file = open('telebot.txt','w')
file.write(tel)
file.close()
large_text = open("telebot.txt", "rb").read()
splitted_text = util.split_string(large_text, 3000)
for text in splitted_text:
bot.send_message(CHAT_ID, text)
print('\n[+] Sent to telegram bot!\n')