Add config file

This commit is contained in:
augustin64 2022-02-17 12:57:51 +01:00
parent 0e5bc99779
commit 3df7d09c40
2 changed files with 54 additions and 37 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 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 create a file named config, containing the following :
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` ```
[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 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.

74
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
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,13 +664,15 @@ 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 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=_mail)
webhookSuccess.send(embed=embed) webhookSuccess.send(embed=embed)
else :
webhookSuccess.send(f'{account} actuellement à {str(point)} points')