This repository has been archived by the owner on May 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FollowerBot.Config.cs
208 lines (201 loc) · 11.7 KB
/
FollowerBot.Config.cs
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Configuration;
namespace FlickrFollowerBot
{
public partial class FollowerBot
{
private class Configuration
{
internal string AddPhotosToFav;
internal string AddContactsToFav;
internal string AddContactsToFollow;
internal string AddContactsToUnfollow;
internal string BotUserSaveFolder;
internal bool BotCacheMyContacts;
internal bool BotSaveAfterEachAction;
internal bool BotSaveOnEnd;
internal bool BotSaveOnLoop;
internal bool BotUsePersistence;
internal float BotSeleniumTimeoutSec;
internal int BotCacheTimeLimitHours;
internal int BotExploreScrools;
internal int BotSearchScrools;
internal int BotFavPictsPerContactMin;
internal int BotFavPictsPerContactMax;
internal int BotUnfollowTaskBatchMinLimit;
internal int BotUnfollowTaskBatchMaxLimit;
internal int BotUsePersistenceLimitHours;
internal int BotContactsFavTaskBatchMinLimit;
internal int BotPhotoFavTaskBatchMinLimit;
internal int BotFollowTaskBatchMinLimit;
internal int BotContactsFavTaskBatchMaxLimit;
internal int BotPhotoFavTaskBatchMaxLimit;
internal int BotFollowTaskBatchMaxLimit;
internal int BotRecentContactPostScrools;
internal int BotStepMaxWaitMs;
internal int BotStepMinWaitMs;
internal int BotWaitTaskMaxWaitMs;
internal int BotWaitTaskMinWaitMs;
internal int BotKeepSomeUnfollowerContacts;
internal string BotTasks;
internal string BotUserEmail;
internal string BotUserPassword;
internal string BotSearchKeywords;
internal string CssContactFollow;
internal string CssContactFollowed;
internal string CssContactPhotos;
internal string CssContactUnfollow;
internal string CssError500;
internal string CssPhotosError404;
internal string CssExploreContact;
internal string CssLoginEmail;
internal string CssLoginMyself;
internal string CssLoginPassword;
internal string CssLoginWarning;
internal string CssModalWaiterBalls;
internal string CssPhotoFave;
internal string CssPhotoFaved;
internal string CssPhotos;
internal string CssPhotosFaved;
internal string CssRecentContactPost;
internal string CssWaiterBalls;
internal string SeleniumRemoteServer;
internal int SeleniumWindowMaxH;
internal int SeleniumWindowMaxW;
internal int SeleniumWindowMinH;
internal int SeleniumWindowMinW;
internal IEnumerable<string> SeleniumBrowserArguments;
internal int BotLoopTaskLimit;
internal int SeleniumRemoteServerWarmUpWaitMs;
internal string UrlContacts;
internal string UrlContactsBlocked;
internal string UrlContactsMutual;
internal string UrlContactsNotFriendAndFamily;
internal string UrlContactsOneWay;
internal string UrlExplore;
internal string UrlLogin;
internal string UrlRecentContactPost;
internal string UrlRoot;
internal string UrlSearch;
}
private Configuration Config;
private void LoadConfig(string[] args)
{
string configJsonPath = ExecPath + "/FlickrFollowerBot.json";
if (File.Exists(configJsonPath))
{
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile(configJsonPath) // default app config
.AddEnvironmentVariables()
.AddCommandLine(args) // priority
.Build();
Config = new Configuration
{
BotUserEmail = config["BotUserEmail"],
BotUserPassword = config["BotUserPassword"],
BotTasks = config["BotTasks"],
BotSearchKeywords = config["BotSearchKeywords"],
AddPhotosToFav = config["AddPhotosToFav"],
AddContactsToFav = config["AddContactsToFav"],
AddContactsToFollow = config["AddContactsToFollow"],
AddContactsToUnfollow = config["AddContactsToUnfollow"],
BotUserSaveFolder = config["BotUserSaveFolder"],
SeleniumRemoteServer = config["SeleniumRemoteServer"],
UrlRoot = config["UrlRoot"],
UrlRecentContactPost = config["UrlRecentContactPost"],
UrlLogin = config["UrlLogin"],
UrlExplore = config["UrlExplore"],
UrlContacts = config["UrlContacts"],
UrlContactsOneWay = config["UrlContactsOneWay"],
UrlContactsMutual = config["UrlContactsMutual"],
UrlContactsBlocked = config["UrlContactsBlocked"],
UrlContactsNotFriendAndFamily = config["UrlContactsNotFriendAndFamily"],
UrlSearch = config["UrlSearch"],
CssRecentContactPost = config["CssRecentContactPost"],
CssError500 = config["CssError500"],
CssPhotosError404 = config["CssPhotosError404"],
CssLoginEmail = config["CssLoginEmail"],
CssLoginPassword = config["CssLoginPassword"],
CssLoginMyself = config["CssLoginMyself"],
CssLoginWarning = config["CssLoginWarning"],
CssContactPhotos = config["CssContactPhotos"],
CssExploreContact = config["CssExploreContact"],
CssModalWaiterBalls = config["CssModalWaiterBalls"],
CssWaiterBalls = config["CssWaiterBalls"],
CssContactFollow = config["CssContactFollow"],
CssContactFollowed = config["CssContactFollowed"],
CssContactUnfollow = config["CssContactUnfollow"],
CssPhotosFaved = config["CssPhotosFaved"],
CssPhotos = config["CssPhotos"],
CssPhotoFave = config["CssPhotoFave"],
CssPhotoFaved = config["CssPhotoFaved"]
};
try
{
// bool
Config.BotUsePersistence = int.Parse(config["BotUsePersistence"], CultureInfo.InvariantCulture) != 0;
Config.BotCacheMyContacts = int.Parse(config["BotCacheMyContacts"], CultureInfo.InvariantCulture) != 0;
Config.BotSaveAfterEachAction = int.Parse(config["BotSaveAfterEachAction"], CultureInfo.InvariantCulture) != 0;
Config.BotSaveOnLoop = int.Parse(config["BotSaveOnLoop"], CultureInfo.InvariantCulture) != 0;
Config.BotSaveOnEnd = int.Parse(config["BotSaveOnEnd"], CultureInfo.InvariantCulture) != 0;
// float
Config.BotSeleniumTimeoutSec = float.Parse(config["BotSeleniumTimeoutSec"], CultureInfo.InvariantCulture);
// int
Config.BotSearchScrools = int.Parse(config["BotSearchScrools"], CultureInfo.InvariantCulture);
Config.BotCacheTimeLimitHours = int.Parse(config["BotCacheTimeLimitHours"], CultureInfo.InvariantCulture);
Config.BotStepMinWaitMs = int.Parse(config["BotStepMinWaitMs"], CultureInfo.InvariantCulture);
Config.BotStepMaxWaitMs = int.Parse(config["BotStepMaxWaitMs"], CultureInfo.InvariantCulture);
Config.BotWaitTaskMinWaitMs = int.Parse(config["BotWaitTaskMinWaitMs"], CultureInfo.InvariantCulture);
Config.BotWaitTaskMaxWaitMs = int.Parse(config["BotWaitTaskMaxWaitMs"], CultureInfo.InvariantCulture);
Config.BotFavPictsPerContactMin = int.Parse(config["BotFavPictsPerContactMin"], CultureInfo.InvariantCulture);
Config.BotFavPictsPerContactMax = int.Parse(config["BotFavPictsPerContactMax"], CultureInfo.InvariantCulture);
Config.BotExploreScrools = int.Parse(config["BotExploreScrools"], CultureInfo.InvariantCulture);
Config.BotContactsFavTaskBatchMinLimit = int.Parse(config["BotContactsFavTaskBatchMinLimit"], CultureInfo.InvariantCulture);
Config.BotPhotoFavTaskBatchMinLimit = int.Parse(config["BotPhotoFavTaskBatchMinLimit"], CultureInfo.InvariantCulture);
Config.BotFollowTaskBatchMinLimit = int.Parse(config["BotFollowTaskBatchMinLimit"], CultureInfo.InvariantCulture);
Config.BotContactsFavTaskBatchMaxLimit = int.Parse(config["BotContactsFavTaskBatchMaxLimit"], CultureInfo.InvariantCulture);
Config.BotPhotoFavTaskBatchMaxLimit = int.Parse(config["BotPhotoFavTaskBatchMaxLimit"], CultureInfo.InvariantCulture);
Config.BotFollowTaskBatchMaxLimit = int.Parse(config["BotFollowTaskBatchMaxLimit"], CultureInfo.InvariantCulture);
Config.BotRecentContactPostScrools = int.Parse(config["BotRecentContactPostScrools"], CultureInfo.InvariantCulture);
Config.BotUnfollowTaskBatchMinLimit = int.Parse(config["BotUnfollowTaskBatchMinLimit"], CultureInfo.InvariantCulture);
Config.BotUnfollowTaskBatchMaxLimit = int.Parse(config["BotUnfollowTaskBatchMaxLimit"], CultureInfo.InvariantCulture);
Config.BotUsePersistenceLimitHours = int.Parse(config["BotUsePersistenceLimitHours"], CultureInfo.InvariantCulture);
Config.BotKeepSomeUnfollowerContacts = int.Parse(config["BotKeepSomeUnfollowerContacts"], CultureInfo.InvariantCulture);
Config.SeleniumWindowMaxH = int.Parse(config["SeleniumWindowMaxH"], CultureInfo.InvariantCulture);
Config.SeleniumWindowMaxW = int.Parse(config["SeleniumWindowMaxW"], CultureInfo.InvariantCulture);
Config.SeleniumWindowMinH = int.Parse(config["SeleniumWindowMinH"], CultureInfo.InvariantCulture);
Config.SeleniumWindowMinW = int.Parse(config["SeleniumWindowMinW"], CultureInfo.InvariantCulture);
Config.SeleniumRemoteServerWarmUpWaitMs = int.Parse(config["SeleniumRemoteServerWarmUpWaitMs"], CultureInfo.InvariantCulture);
if (int.TryParse(config["BotLoopTaskLimit"], out int tmpBotLoopTaskLimit))
{
Config.BotLoopTaskLimit = tmpBotLoopTaskLimit;
}
else
{
Config.BotLoopTaskLimit = 0;
}
if (!string.IsNullOrWhiteSpace(config["SeleniumBrowserArguments"]))
{
Config.SeleniumBrowserArguments = config["SeleniumBrowserArguments"].Split('|', StringSplitOptions.RemoveEmptyEntries);
}
else
{
Config.SeleniumBrowserArguments = Enumerable.Empty<string>();
}
}
catch (FormatException ex)
{
throw new FormatException("Bot settings format error, check your settings", ex);
}
}
else
{
throw new FormatException("Configuration file missing : " + configJsonPath);
}
}
}
}