-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinal.py
131 lines (103 loc) · 3.92 KB
/
final.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
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
import csv
from email import message
import telebot
from telethon.sync import TelegramClient
from telethon.tl.types import InputPeerUser, InputPeerChannel
from telethon import TelegramClient, sync, events
from datetime import datetime,date
def main():
api_id = ''
api_hash = ''
# receiver user_id and access_hash, use
#change user id
user_id = 0
# set it as default 0
access_hash = 0
# your phone number with country code
# example +9233333333333
phone = ''
#path to chrome web driver
PATH = "chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://twitter.com/login")
## credentials
sleep(3)
cred = open('credentials.txt','rt')
context = cred.read()
context = context.split('\n')
user_name = context[0]
user_password = context[1]
# Setup the log in
sleep(5)
username = driver.find_element(By.XPATH,"//input[@name='text']")
username.send_keys(user_name)
next_button = driver.find_element(By.XPATH,"//span[contains(text(),'Next')]")
next_button.click()
sleep(3)
password = driver.find_element(By.XPATH,"//input[@name='password']")
password.send_keys(user_password)
log_in = driver.find_element(By.XPATH,"//span[contains(text(),'Log in')]")
log_in.click()
sleep(3)
profile = driver.find_element(By.XPATH,'//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div/div/div[2]/div/div[2]/div[1]/div/div/div/div[1]/div/div[2]/div/div[2]/div/a/div[4]/div')
profile.click()
sleep(3)
follower = driver.find_element(By.XPATH,'//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div/div/div[2]/div/div/div/div[2]/div[4]/div[2]/a')
follower.click()
sleep(5)
followers = driver.find_elements(By.XPATH,'//div[@aria-label="Timeline: Followers"]//a[@role="link"]/div/div[@dir="ltr"]/span')
old_followers = []
new_followers = []
filereader = csv.reader(open("followers.csv","r"),delimiter = ",")
next(filereader) # skipping the column of the csv
for row in filereader:
old_followers.append(row[0])
for i in followers:
rep = i.text.replace('@','')
if rep not in old_followers:
new_followers.append([rep,f'https://twitter.com/{rep}'])
# updating the old csv to save the new followers to the existing ones.
with open('followers.csv','r+') as file:
file.read()
writer = csv.writer(file)
writer.writerows(new_followers)
file.close()
driver.close()
# Telegram
# creating a telegram session and assigning
# it to a variable client
client = TelegramClient('session', api_id, api_hash)
# connecting and building the session
client.connect()
# in case of script ran first time it will
# ask either to input token or otp sent to
# number or sent or your telegram id
if not client.is_user_authorized():
client.send_code_request(phone)
# signing in the client
client.sign_in(phone, input('Enter the code: '))
try:
# my user_id and access_hash for reference
receiver = InputPeerUser(user_id, 0)
today = date.today()
now = datetime.now()
day = today.strftime("%b-%d-%Y")
current_time = now.strftime("%H:%M:%S")
message = f"New Followers \n{day} {current_time} \n Count : {len(followers)}"
client.send_message(receiver,message, parse_mode='html')
if len(followers) != 0:
for row in new_followers:
message = f"{row[0]}, {row[1]}"
client.send_message(receiver,message, parse_mode='html')
except Exception as e:
#prints error
print(e);
# disconnecting the telegram session
client.disconnect()
if __name__ == "__main__":
main()