Skip to content

Commit

Permalink
Telegram support added and minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lorcalhost committed Feb 19, 2019
1 parent d359d90 commit c636d8c
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 75 deletions.
61 changes: 51 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Romance breaker relies on a few things, here is what to do to get them:
###### For Linux:
Run these commands in your preferred terminal application
```shell=
sudo apt-get install python-dev libxml2-dev libxslt1-dev zlib1g-dev
pip install fbchat bs4
sudo apt-get install python3-pip
pip3 install fbchat bs4
git clone https://github.com/lorcalhost/RomanceBreaker.git
```
###### For Windows
Expand All @@ -40,20 +40,61 @@ From *Android* you will only be able to run the Facebook Messenger version, here
```termux-setup-storage``` and allow storage access
```shell=
cd storage/downloads
pkg install python git
pip install fbchat requests bs4 enum
pkg install python3 git
pip3 install fbchat requests bs4 enum
git clone https://github.com/lorcalhost/RomanceBreaker.git
```
Please note that every time you restart your device, you will have to re run the commands in the *How to run* section

### How to run
###### Linux:
Simply ```cd RomanceBreaker``` and ```python RomanceBreaker.py```
###### Android:
Simply ```cd storage/downloads/RomanceBreaker``` and ```python RomanceBreaker.py```
For *Android* users: you will also need to press ```"ACQUIRE WAKELOCK"``` in the Termux notification to enable the script to run in the background without the process being killed

---
# Telegram
### Installation on PC

Romance breaker relies on a few things, here is what to do to get them:

- Python3 is needed get it from [here](https://www.python.org/downloads/)
###### For Linux:
Run these commands in your preferred terminal application
```shell=
sudo apt-get install python3-pip
pip3 install telethon bs4
git clone https://github.com/lorcalhost/RomanceBreaker.git
```
###### For Windows
- Also install git from [here](https://git-scm.com/download/win)
- Make sure you run all the commands from git
```shell=
sudo pip install telethon bs4
git clone https://github.com/lorcalhost/RomanceBreaker.git
```

### Installation on Android
As it was highly requested by the plebs without a raspberry pi:
From *Android* you will only be able to run the Facebook Messenger version, here are the instructions:
- First download and install [Termux from the Google Play Store](https://play.google.com/store/apps/details?id=com.termux)
- Then run the following commands:

```termux-setup-storage``` and allow storage access
```shell=
cd storage/downloads
pkg install python3 git
pip3 install telethon requests bs4 enum
git clone https://github.com/lorcalhost/RomanceBreaker.git
```
Please note that every time you restart your device, you will have to re run the commands in the *How to run* section

For *Android* users: you will also need to press ```"ACQUIRE WAKELOCK"``` in the Termux notification to enable the script to run in the background without the process being killed

To make the telegram script work you'll also need to update the `config.py` file with your login info:
- Log in to your Telegram core: https://my.telegram.org.
- Go to ‘API development tools’ and fill out the form.
- Create an app
- You will get the `api_id` and `api_hash` parameters required for user authorization (to put in the config.py file)

Password only required if you have two-step verification enabled

---

# WhatsApp and SMS
Expand All @@ -76,7 +117,7 @@ git clone https://github.com/lorcalhost/RomanceBreaker.git
- Also install git from [here](https://git-scm.com/download/win)
- Make sure you run all the commands from git
```shell=
sudo pip install selenium bs4 pyperclip
pip install selenium bs4 pyperclip
git clone https://github.com/lorcalhost/RomanceBreaker.git
```

Expand Down
17 changes: 15 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
_____ ____ _
| __ \ | _ \ | |
Expand All @@ -9,10 +9,23 @@
"""

# CHOOSE WHICH PLATFORM YOU ARE ON:
# Windows/Linux (case sensitive)
currentOS = "Windows"

# CUSTOM MESSAGES SETUP
# Edit or add your own custom messages by putting your message between "s and using the same format below
custom_morning_messages = ["Good morning beautiful ♥♥♥", "I'm too lazy", "To write messages on my own", "Custom message #4"]

# CUSTOM TIMES SETUP
# Put here your own custom time interval, make sure the hour is always two digits
custom_time_interval = ["04:20", "16:20"]
custom_time_interval = ["04:20", "16:20"]

# TELEGRAM LOGIN SETUP:
telegram_phone = "+391234567890"
telegram_username = "lorcalhost"
# Password required only if you have two-step verification enabled
telegram_password = "MY_PASSWORD"
# (Get api_id and api_hash from https://my.telegram.org then API development tools and create an App)
tg_api_id = 123456
tg_api_hash = '133780563f161f870b2b7sk72ba1c36f'
23 changes: 18 additions & 5 deletions romanceBreaker.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
#!/usr/bin/python3
import sys
import os
import config

command = "python"
if config.currentOS is "Linux":
command += "3 src/"
else:
command += " src\\"


def prnthelp():
print("Welcome to the RomanceBreaker user guide\nPlease refer to the Github page for detailed setup instructions")
print("\nList of commands:\nwhatsapp or -w ---> launches RomanceBreaker in WhatsApp mode\nmessenger or -m ---> launches RomanceBreaker in Messenger mode\nsms or -s ---> launches RomanceBreaker in SMS mode")
print("\nList of commands:\nwhatsapp or -w ---> launches RomanceBreaker in WhatsApp mode\nmessenger or -m ---> launches RomanceBreaker in Messenger mode\nsms or -s ---> launches RomanceBreaker in SMS mode\ntelegram or -t ---> launches RomanceBreaker in Telegram mode")
print("help or -h or man ---> Launches user guide\nupdate ---> Updates RomanceBreaker from the github repo")


try:
if str(sys.argv[1]) == "whatsapp" or str(sys.argv[1]) == "-w":
print("WHATSAPP MODE")
os.system("python whatsappRB.py")
os.system("{}whatsappRB.py" .format(command))
elif str(sys.argv[1]) == "messenger" or str(sys.argv[1]) == "-m":
print("MESSENGER MODE")
os.system("python messengerRB.py")
os.system("{}messengerRB.py" .format(command))
elif str(sys.argv[1]) == "sms" or str(sys.argv[1]) == "-s":
print("SMS MODE")
os.system("python smsRB.py")
os.system("{}smsRB.py" .format(command))
elif str(sys.argv[1]) == "telegram" or str(sys.argv[1]) == "-t":
print("TELEGRAM MODE")
os.system("{}telegramRB.py" .format(command))
elif str(sys.argv[1]) == "help" or str(sys.argv[1]) == "-h" or str(sys.argv[1]) == "man":
prnthelp()
elif str(sys.argv[1]) == "update":
os.system("git pull")
except:
print("Invalid arguments\nRun python romanceBreaker.py -h to look at the commands manual")
print("Invalid arguments\nTry running {} romanceBreaker.py -h to show the list of commands" .format(command))
25 changes: 7 additions & 18 deletions messengerRB.py → src/messengerRB.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import random
from fbchat.models import ThreadType, Message
from getpass import getpass
import os,sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
import randomTime

randTimeHour = 0
randTimeMinute = 0

#Getting username & pwd
username = input("Username: ")
Expand All @@ -35,23 +36,11 @@ def morningMessage():
morningMessage()
return

def newRandTime():
global randTimeHour
global randTimeMinute
randTimeHour = random.randint(int(config.custom_time_interval[0][0:2]), int(config.custom_time_interval[1][0:2]))
if int(randTimeHour) == int(config.custom_time_interval[1][0:2]):
randTimeMinute = random.randint(0, int(config.custom_time_interval[1][3:5]))
elif int(randTimeHour) == int(config.custom_time_interval[0][0:2]):
randTimeMinute = random.randint(int(config.custom_time_interval[1][3:5]), 59)
else:
randTimeMinute = random.randint(0, 59)
print("I'll send a message at {}:{}..." .format(randTimeHour.zfill(2), randTimeMinute.zfill(2)))
return

newRandTime()
randTimeHour, randTimeMinute = randomTime.new(config.custom_time_interval)

while True:
if int(datetime.datetime.today().hour) == int(randTimeHour) and int(datetime.datetime.today().minute) == int(randTimeMinute):
morningMessage()
newRandTime()
time.sleep(60) #Wait one minute to check if it's #morningtime
randTimeHour, randTimeMinute = randomTime.new(
config.custom_time_interval)
time.sleep(60) #Wait one minute to check if it's #morningtime
14 changes: 14 additions & 0 deletions src/randomTime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
import random

def new(interval):
hour = random.randint(int(interval[0][0:2]), int(interval[1][0:2]))
if int(hour) == int(interval[1][0:2]):
minute = random.randint(0, int(interval[1][3:5]))
elif int(hour) == int(interval[0][0:2]):
minute = random.randint(int(interval[1][3:5]), 59)
else:
minute = random.randint(0, 59)
print("I'll send a message at {}:{}..." .format(
hour.zfill(2), minute.zfill(2)))
return hour, minute
37 changes: 16 additions & 21 deletions smsRB.py → src/smsRB.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import datetime
import random
import pyperclip
import os,sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
import randomTime


def morningMessage():
#Sending message
Expand All @@ -18,17 +22,20 @@ def morningMessage():
msg = random.choice(config.custom_morning_messages)
try:
pyperclip.copy(bae)
searchbar = driver.find_elements_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div/div/div/div[1]/div[3]/div/div[2]/div[3]')[0]
searchbar = driver.find_elements_by_xpath(
'//*[@id="yDmH0d"]/c-wiz/div/div/div/div/div/div[1]/div[3]/div/div[2]/div[3]')[0]
searchbar.click()
time.sleep(1)
newmessage = driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div/div/div/div[2]/div/div[2]/div/div[2]/div/div/div/div[1]/div/div[1]/input')
newmessage = driver.find_element_by_xpath(
'//*[@id="yDmH0d"]/c-wiz/div/div/div/div/div/div[2]/div/div[2]/div/div[2]/div/div/div/div[1]/div/div[1]/input')
newmessage.send_keys(Keys.CONTROL, 'v')
msg = random.choice(config.custom_morning_messages)
pyperclip.copy(msg)
time.sleep(5)
newmessage.send_keys(Keys.ENTER)
time.sleep(6.5)
message = driver.find_elements_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div/div/div/div[2]/div/div[3]/div/div/div[3]/div[2]/div[1]/div/div[2]/div/div[1]')[0]
message = driver.find_elements_by_xpath(
'//*[@id="yDmH0d"]/c-wiz/div/div/div/div/div/div[2]/div/div[3]/div/div/div[3]/div[2]/div[1]/div/div[2]/div/div[1]')[0]
message.send_keys(Keys.CONTROL, 'v')
message.send_keys(Keys.ENTER)
print("Message {} successfully sent to {}" .format(msg, bae))
Expand All @@ -38,34 +45,22 @@ def morningMessage():
pass
return

def newRandTime():
global randTimeHour
global randTimeMinute
randTimeHour = random.randint(int(config.custom_time_interval[0][0:2]), int(config.custom_time_interval[1][0:2]))
if int(randTimeHour) == int(config.custom_time_interval[1][0:2]):
randTimeMinute = random.randint(0, int(config.custom_time_interval[1][3:5]))
elif int(randTimeHour) == int(config.custom_time_interval[0][0:2]):
randTimeMinute = random.randint(int(config.custom_time_interval[1][3:5]), 59)
else:
randTimeMinute = random.randint(0, 59)
print("I'll send a message at {}:{}...".format(randTimeHour.zfill(2), randTimeMinute.zfill(2)))
return

#Getting username & pwd
bae = input("Name of your bae: ")
print("A popup view of Google Messages will now open,\nScan the QR code in the page via your app\nDon't close the popup")
time.sleep(5)

driver = webdriver.Chrome('./chromedriver')
driver = webdriver.Chrome(
'{}/chromedriver'.format(os.path.dirname(os.path.realpath('__file__'))))
driver.get("https://messages.android.com/")
wait = WebDriverWait(driver, 600)

randTimeHour = 0
randTimeMinute = 0
newRandTime()
randTimeHour, randTimeMinute = randomTime.new(config.custom_time_interval)

while True:
if int(datetime.datetime.today().hour) == int(randTimeHour) and int(datetime.datetime.today().minute) == int(randTimeMinute):
morningMessage()
newRandTime()
time.sleep(60) #Wait one minute to check if it's #morningtime
randTimeHour, randTimeMinute = randomTime.new(
config.custom_time_interval)
time.sleep(60) # Wait one minute to check if it's #morningtime
41 changes: 41 additions & 0 deletions src/telegramRB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
import time
import datetime
import random
import os,sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
import randomTime

#Getting username & pwd
client = TelegramClient(config.telegram_username,
config.tg_api_id, config.tg_api_hash)
client.start(config.telegram_phone, config.telegram_password)

#Getting recipient
name = input("Username of your bae: ")
friends = client.searchForUsers(name)
bae = friends[0]


def morningMessage():
#Sending message
msg = random.choice(config.custom_morning_messages)
global client
global bae
sent = client.send_message(bae, msg)
if sent:
print("Message '{}' sent successfully!\nWaiting for next scheduled time..." .format(msg))
else:
print("There was an error trying to send the message")
return


randTimeHour, randTimeMinute = randomTime.new(config.custom_time_interval)

while True:
if int(datetime.datetime.today().hour) == int(randTimeHour) and int(datetime.datetime.today().minute) == int(randTimeMinute):
morningMessage()
randTimeHour, randTimeMinute = randomTime.new(
config.custom_time_interval)
time.sleep(60) # Wait one minute to check if it's #morningtime
28 changes: 9 additions & 19 deletions whatsappRB.py → src/whatsappRB.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import datetime
import random
import pyperclip
import os,sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
import randomTime

def morningMessage():
#Sending message
Expand Down Expand Up @@ -44,34 +47,21 @@ def morningMessage():
pass
return

def newRandTime():
global randTimeHour
global randTimeMinute
randTimeHour = random.randint(int(config.custom_time_interval[0][0:2]), int(config.custom_time_interval[1][0:2]))
if int(randTimeHour) == int(config.custom_time_interval[1][0:2]):
randTimeMinute = random.randint(0, int(config.custom_time_interval[1][3:5]))
elif int(randTimeHour) == int(config.custom_time_interval[0][0:2]):
randTimeMinute = random.randint(int(config.custom_time_interval[1][3:5]), 59)
else:
randTimeMinute = random.randint(0, 59)
print("I'll send a message at {}:{}..." .format(randTimeHour.zfill(2), randTimeMinute.zfill(2)))
return

#Getting username & pwd
bae = input("Name of your bae: ")
print("A popup view of WhatsApp web will now open,\nScan the QR code in the page via your app\nDon't close the popup")
time.sleep(5)

driver = webdriver.Chrome('./chromedriver')
driver = webdriver.Chrome(
'{}/chromedriver'.format(os.path.dirname(os.path.realpath('__file__'))))
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)

randTimeHour = 0
randTimeMinute = 0
newRandTime()
randTimeHour, randTimeMinute = randomTime.new(config.custom_time_interval)

while True:
if int(datetime.datetime.today().hour) == int(randTimeHour) and int(datetime.datetime.today().minute) == int(randTimeMinute):
morningMessage()
newRandTime()
time.sleep(60) #Wait one minute to check if it's #morningtime
randTimeHour, randTimeMinute = randomTime.new(
config.custom_time_interval)
time.sleep(60) #Wait one minute to check if it's #morningtime

1 comment on commit c636d8c

@lorcalhost
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #1 #2 #4

Please sign in to comment.