-
-
Notifications
You must be signed in to change notification settings - Fork 271
/
main.py
175 lines (154 loc) · 6.62 KB
/
main.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import argparse
import json
import logging
import logging.handlers as handlers
import random
import sys
from pathlib import Path
from src import Browser, DailySet, Login, MorePromotions, PunchCards, Searches
from src.constants import VERSION
from src.loggingColoredFormatter import ColoredFormatter
from src.notifier import Notifier
POINTS_COUNTER = 0
def main():
setupLogging()
args = argumentParser()
notifier = Notifier(args)
loadedAccounts = setupAccounts()
for currentAccount in loadedAccounts:
try:
executeBot(currentAccount, notifier, args)
except Exception as e:
logging.exception(f"{e.__class__.__name__}: {e}")
def setupLogging():
format = "%(asctime)s [%(levelname)s] %(message)s"
terminalHandler = logging.StreamHandler(sys.stdout)
terminalHandler.setFormatter(ColoredFormatter(format))
(Path(__file__).resolve().parent / "logs").mkdir(parents=True, exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format=format,
handlers=[
handlers.TimedRotatingFileHandler(
"logs/activity.log",
when="midnight",
interval=1,
backupCount=2,
encoding="utf-8",
),
terminalHandler,
],
)
def argumentParser() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Microsoft Rewards Farmer")
parser.add_argument(
"-v", "--visible", action="store_true", help="Optional: Visible browser"
)
parser.add_argument(
"-l", "--lang", type=str, default=None, help="Optional: Language (ex: en)"
)
parser.add_argument(
"-g", "--geo", type=str, default=None, help="Optional: Geolocation (ex: US)"
)
parser.add_argument(
"-p",
"--proxy",
type=str,
default=None,
help="Optional: Global Proxy (ex: http://user:pass@host:port)",
)
parser.add_argument(
"-t",
"--telegram",
metavar=("TOKEN", "CHAT_ID"),
nargs=2,
type=str,
default=None,
help="Optional: Telegram Bot Token and Chat ID (ex: 123456789:ABCdefGhIjKlmNoPQRsTUVwxyZ 123456789)",
)
parser.add_argument(
"-d",
"--discord",
type=str,
default=None,
help="Optional: Discord Webhook URL (ex: https://discord.com/api/webhooks/123456789/ABCdefGhIjKlmNoPQRsTUVwxyZ)",
)
return parser.parse_args()
def bannerDisplay():
farmerBanner = """
███╗ ███╗███████╗ ███████╗ █████╗ ██████╗ ███╗ ███╗███████╗██████╗
████╗ ████║██╔════╝ ██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝██╔══██╗
██╔████╔██║███████╗ █████╗ ███████║██████╔╝██╔████╔██║█████╗ ██████╔╝
██║╚██╔╝██║╚════██║ ██╔══╝ ██╔══██║██╔══██╗██║╚██╔╝██║██╔══╝ ██╔══██╗
██║ ╚═╝ ██║███████║ ██║ ██║ ██║██║ ██║██║ ╚═╝ ██║███████╗██║ ██║
╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝"""
logging.error(farmerBanner)
logging.warning(
f" by Charles Bel (@charlesbel) version {VERSION}\n"
)
def setupAccounts() -> dict:
accountPath = Path(__file__).resolve().parent / "accounts.json"
if not accountPath.exists():
accountPath.write_text(
json.dumps(
[{"username": "Your Email", "password": "Your Password"}], indent=4
),
encoding="utf-8",
)
noAccountsNotice = """
[ACCOUNT] Accounts credential file "accounts.json" not found.
[ACCOUNT] A new file has been created, please edit with your credentials and save.
"""
logging.warning(noAccountsNotice)
exit()
loadedAccounts = json.loads(accountPath.read_text(encoding="utf-8"))
random.shuffle(loadedAccounts)
return loadedAccounts
def executeBot(currentAccount, notifier: Notifier, args: argparse.Namespace):
logging.info(
f'********************{currentAccount.get("username", "")}********************'
)
with Browser(mobile=False, account=currentAccount, args=args) as desktopBrowser:
accountPointsCounter = Login(desktopBrowser).login()
startingPoints = accountPointsCounter
logging.info(
f"[POINTS] You have {desktopBrowser.utils.formatNumber(accountPointsCounter)} points on your account !"
)
DailySet(desktopBrowser).completeDailySet()
PunchCards(desktopBrowser).completePunchCards()
MorePromotions(desktopBrowser).completeMorePromotions()
(
remainingSearches,
remainingSearchesM,
) = desktopBrowser.utils.getRemainingSearches()
if remainingSearches != 0:
accountPointsCounter = Searches(desktopBrowser).bingSearches(
remainingSearches
)
if remainingSearchesM != 0:
desktopBrowser.closeBrowser()
with Browser(
mobile=True, account=currentAccount, args=args
) as mobileBrowser:
accountPointsCounter = Login(mobileBrowser).login()
accountPointsCounter = Searches(mobileBrowser).bingSearches(
remainingSearchesM
)
logging.info(
f"[POINTS] You have earned {desktopBrowser.utils.formatNumber(accountPointsCounter - startingPoints)} points today !"
)
logging.info(
f"[POINTS] You are now at {desktopBrowser.utils.formatNumber(accountPointsCounter)} points !\n"
)
notifier.send(
"\n".join(
[
"Microsoft Rewards Farmer",
f"Account: {currentAccount.get('username', '')}",
f"Points earned today: {desktopBrowser.utils.formatNumber(accountPointsCounter - startingPoints)}",
f"Total points: {desktopBrowser.utils.formatNumber(accountPointsCounter)}",
]
)
)
if __name__ == "__main__":
main()