Merge pull request #3 from augustin64/master

Add config file
This commit is contained in:
piair338 2022-02-17 13:49:49 +01:00 committed by GitHub
commit 72e42f5991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 33 deletions

View File

@ -2,8 +2,19 @@
A Microsoft reward automator, designed to work headless on a raspberry pi. Tested with a pi 3b+ and a pi 4 2Gb . A Microsoft reward automator, designed to work headless on a raspberry pi. Tested with a pi 3b+ and a pi 4 2Gb .
Using a discord bot to log eveything. Using a discord webhook to log everything.
Using Selenium and geckodriver. Using Selenium and geckodriver.
You have to create a file named config, containing the following :
```
[DEFAULT]
motpath = # Path to liste.txt file
logpath = # Path to login.csv file
successlink = # Link of the webhook to log success
errorlink = # Link of the webhook to log errors
embeds = True # Send embeds instead of text
Headless = True # Run Headless
Log = False # Show Logs
```
you have to put your credentials in the same folder as the script, in a file named `login.csv`. You have to put info this way : `email,password` you have to put your credentials in the same folder as the script, in a file named `login.csv`. You have to put info this way : `email,password`
you have to put two discord webhook links, the first one for success and the second one for failure, separated with a coma, in the same folder as the script, in a file named `webhook.txt`
you have to put a list with a dictionnary in the same folder as the script, in a file named `liste.txt` .It should have a lot of words, used to make random search on bing, as shown in the example file. you have to put a list with a dictionnary in the same folder as the script, in a file named `liste.txt` .It should have a lot of words, used to make random search on bing, as shown in the example file.

65
V4.py
View File

@ -1,5 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import asyncio import asyncio
import configparser
import os import os
from csv import reader from csv import reader
from os import path, sys, system from os import path, sys, system
@ -20,34 +21,28 @@ from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
main = True main = True
Headless = True
Log = False
SucessEmbed = False
IsLinux = platform == "linux" IsLinux = platform == "linux"
print("Linux : "+ str(IsLinux)) print("Linux : "+ str(IsLinux))
config_path = "./config"
config = configparser.ConfigParser()
config.read(config_path)
MotPath = config["DEFAULT"]["motpath"]
LogPath = config["DEFAULT"]["logpath"]
SuccessLink = config["DEFAULT"]["successlink"]
ErrorLink = config["DEFAULT"]["errorlink"]
embeds = config["DEFAULT"]["embeds"] == "True"
if IsLinux : Headless = config["DEFAULT"]["headless"] == "True"
MotPath = "/home/pi/MsReward/liste.txt" Log = config["DEFAULT"]["log"] == "True"
LogPath= "/home/pi/MsReward/login.csv"
WebHookPath = "/home/pi/MsReward/webhook.txt"
else :
MotPath = resource_path('D:\Documents\Dev\MsReward\liste/liste.txt')
LogPath = resource_path('D:\Documents\Dev\MsReward\login/login.csv')
WebHookPath = resource_path('D:\Documents\Dev\MsReward/token/webhook.txt')
system("")
g = open(MotPath, "r" , encoding="utf-8") g = open(MotPath, "r" , encoding="utf-8")
Liste_de_mot=(list(g.readline().split(','))) Liste_de_mot=(list(g.readline().split(',')))
g.close() g.close()
g = open(WebHookPath,"r")
SuccessLink, ErrorLink = g.readline().split(',')
g.close
webhookSuccess = Webhook.from_url(SuccessLink, adapter=RequestsWebhookAdapter()) webhookSuccess = Webhook.from_url(SuccessLink, adapter=RequestsWebhookAdapter())
webhookFailure = Webhook.from_url(ErrorLink, adapter=RequestsWebhookAdapter()) webhookFailure = Webhook.from_url(ErrorLink, adapter=RequestsWebhookAdapter())
@ -142,17 +137,26 @@ def LogError(message,log = Log, Mobdriver = None):
gdriver.save_screenshot("screenshot.png") gdriver.save_screenshot("screenshot.png")
embed = discord.Embed( if embeds :
title="An Error has occured", embed = discord.Embed(
description=str(message), title="An Error has occured",
url = ListTabs(Mdriver=Mobdriver)[0], description=str(message),
colour = Colour.red() url = ListTabs(Mdriver=Mobdriver)[0],
) colour = Colour.red()
file = discord.File("screenshot.png") )
embed.set_image(url="attachment://screenshot.png") file = discord.File("screenshot.png")
embed.set_footer(text=_mail) embed.set_image(url="attachment://screenshot.png")
webhookFailure.send(embed=embed, file=file) embed.set_footer(text=_mail)
webhookFailure.send(file=discord.File('page.html')) webhookFailure.send(embed=embed, file=file)
webhookFailure.send(file=discord.File('page.html'))
else :
webhookFailure.send(content="------------------------------------\n" + _mail)
webhookFailure.send(ListTabs(Mdriver=Mobdriver))
webhookFailure.send(str(message))
CustomSleep(1)
webhookFailure.send(file=discord.File('screenshot.png'))
webhookFailure.send(file=discord.File('page.html'))
webhookFailure.send("------------------------------------")
def progressBar(current, total=30, barLength = 20, name ="Progress"): def progressBar(current, total=30, barLength = 20, name ="Progress"):
@ -660,15 +664,16 @@ def LogPoint(account="unknown"): #log des points sur discord
CustomSleep(uniform(3,20)) CustomSleep(uniform(3,20))
account = account.split('@')[0] account = account.split('@')[0]
if SucessEmbed :
if embeds:
embed = discord.Embed( embed = discord.Embed(
title=f"{account} actuellement à {str(point)} points", title=f"{account} actuellement à {str(point)} points",
colour = Colour.green() colour = Colour.green()
) )
embed.set_footer(text=_mail) embed.set_footer(text=account)
webhookSuccess.send(embed=embed) webhookSuccess.send(embed=embed)
else : else :
webhookSuccess.send(_mail + "actuellement à" +str(point) + "points") webhookSuccess.send(f'{account} actuellement à {str(point)} points')
def Fidelité(): def Fidelité():