Skip to content

Commit

Permalink
Merge pull request #24 from gholamiayub/editunusedimport
Browse files Browse the repository at this point in the history
Fixes #23 

Rewrite imports to only use modules in use
  • Loading branch information
RhinosF1 authored May 16, 2020
2 parents 6931713 + 25829e4 commit 8f6755a
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import time
import requests
import stdiomask
import sys
from time import sleep
from requests import Session
from stdiomask import getpass
from sys import argv, exit
from random import getrandbits

# Define the functions here


def remove():
time.sleep(2)
sleep(2)
input("Press enter to continue or ctrl+c to quit")
file = open('userinfo.cfg', 'r')
userdata = file.read()
Expand All @@ -34,7 +34,7 @@ def remove():
'User-Agent': 'BOT: ' + opusername + '@TestWikiAutoInactive-v1rc1',
'From': fromheader
}
S = requests.Session()
S = Session()
URL = "https://publictestwiki.com/w/api.php"
# Step 1: Retrieve a login token
PARAMS_1 = {
Expand All @@ -48,8 +48,8 @@ def remove():
LOGIN_TOKEN = DATA["query"]["tokens"]["logintoken"]
# Step 2: Send a post request to log in. See
# https://www.mediawiki.org/wiki/Manual:Bot_passwords
time.sleep(5) # wait 5s to avoid throttling
password = stdiomask.getpass()
sleep(5) # wait 5s to avoid throttling
password = getpass()
PARAMS_2 = {
"action": "login",
"lgname": username,
Expand Down Expand Up @@ -88,7 +88,7 @@ def remove():
username +
',')
configfile.close()
time.sleep(5) # hold for 5s to avoid throttling
sleep(5) # hold for 5s to avoid throttling
# Step 3: Obtain a Userrights token
PARAMS_3 = {
"action": "query",
Expand All @@ -107,11 +107,11 @@ def remove():
usertemp = input("User to remove: ")
userlist.append(usertemp)
count = count + 1
time.sleep(0.5)
sleep(0.5)
count = 0
while count < len(userlist):
inactiveuser = userlist[count]
time.sleep(10) # wait 10 seconds before write api
sleep(10) # wait 10 seconds before write api
# Step 4: Request to add or remove a user from a group
PARAMS_4 = {
"action": "userrights",
Expand All @@ -124,16 +124,16 @@ def remove():
R = S.post(URL, data=PARAMS_4, headers=headers)
DATA = R.json()
print(DATA)
time.sleep(2)
sleep(2)
print('Generating mass message text..')
print('{{subst:Inactivity|user=' + opusername + '}}')
time.sleep(5)
sleep(5)
print("Thanks for using! Good bye.")
sys.exit()
exit()


def notify():
time.sleep(10)
sleep(10)
consul = input("What is your username? ")
removedate = input("Removal date: ")
date = input("Today's Date: ")
Expand All @@ -144,20 +144,20 @@ def notify():
usertemp = input("User to remove: ")
userlist.append(usertemp)
count = count + 1
time.sleep(0.5)
sleep(0.5)
print("Generating mass message list....")
time.sleep(2)
sleep(2)
count = 0
while count < len(userlist):
print("User Talk:" + str(userlist[count]))
count = count + 1
time.sleep(0.5)
sleep(0.5)
print("Generating mass message text....")
time.sleep(2)
sleep(2)
print("{{subst:InactiveReminder|DATE=" + removedate +
"|sig=~~~ for [[User:" + consul + "|" + consul + "]]}}")
print("Generating Community Noticeboard post")
time.sleep(2)
sleep(2)
print("==Inactive Rights Removal - " + date + "==")
print(
"The rights of the following users will be removed on or after " +
Expand All @@ -172,23 +172,23 @@ def notify():
print(":~~~")
print(":For the Consul Team")
print(":~~~~~")
time.sleep(5)
sleep(5)
print("Thanks for using! Good bye.")


try:
if sys.argv[1] == 'remove':
if argv[1] == 'remove':
print("Running Script in Remove Mode")
print("Welcome to the TestWiki:Inactivity Script")
print("This script may only be used by consuls")
print("Please ensure notifications were sent > 7 days ago and the users are still inacitve")
remove()
elif sys.argv[1] == 'notify':
elif argv[1] == 'notify':
print("Running Script in Notify Mode")
print("Before we begin, please run the findInactive script on https://publictestwiki.com")
print("The notification process will begin in 10 seconds")
notify()
elif sys.argv[1] == 'help':
elif argv[1] == 'help':
print("Commands are:")
print("remove - Removes rights from inactive users")
print("notify - Generates messages for inactive users")
Expand All @@ -198,4 +198,4 @@ def notify():
except IndexError as e:
print(e)
print("Please specify an action (remove, notify)")
sys.exit()
exit()

0 comments on commit 8f6755a

Please sign in to comment.