From 9fe704ad229bdf2733e6cee7a9b1696577b80689 Mon Sep 17 00:00:00 2001 From: Alessio Date: Dec 09 2019 14:38:11 +0000 Subject: As agreed, remove the scripts from here --- diff --git a/scripts/checkstatus/README.md b/scripts/checkstatus/README.md deleted file mode 100644 index 32d8280..0000000 --- a/scripts/checkstatus/README.md +++ /dev/null @@ -1,23 +0,0 @@ -Check FAS user status. - -## Configuration: -rename `myconfig.cfg.example` to `myconfig.cfg` and edit it accordingly (it contains your FAS credentials). - -## Syntax: -`python3 check.py username days` - -Where `username` is the FAS user to check and `days` is the number of days to check on datagrepper in order to -get a list of activities logged from the fedmsg bus. - -## Results -The script output is as follow: - -* Username -* Human name -* Last seen (date of last FAS login) -* Groups - * list of FAS group membership, status and approval date - * total number of groups the user is member of -* Activities in the last X days: - * a list of activity topics grabbed from datagrepper - * total number of activities diff --git a/scripts/checkstatus/check.py b/scripts/checkstatus/check.py deleted file mode 100644 index f8d2ce6..0000000 --- a/scripts/checkstatus/check.py +++ /dev/null @@ -1,94 +0,0 @@ -import time -import datetime -import dateutil.relativedelta -import configparser -import requests -from fedora.client.fas2 import AccountSystem -import sys - -configfile = 'myconfig.cfg' - -config = configparser.ConfigParser() -config.read(configfile) -options = config.options('FAS') -userdata = {} - -for opt in options: - userdata[opt] = config.get('FAS', opt) - -user = userdata['user'] -password = userdata['pass'] - -fas = AccountSystem(username=user, password=password) -fas.timeout = 600 -fas.retries = 3 - -activity_baseurl = 'https://apps.fedoraproject.org/datagrepper/raw' - - -def getactivitycount(username,days): - days = int(days) - today = datetime.date.today() - d = datetime.datetime.strptime(today.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S") - d = d - dateutil.relativedelta.relativedelta(days=days) - start = time.mktime(datetime.datetime.strptime(str(d), "%Y-%m-%d %H:%M:%S").timetuple()) - - activity_params = {'rows_per_page': 100, 'size': 'small', 'start': start, 'user': username} - - activity_results = requests.get(activity_baseurl, params=activity_params).json() - - pages = activity_results['pages'] - - for i in range(0, pages): - # print("aaaaaaaaaaaaaaaaaa",i) - activity_params2 = {'page': 1, 'rows_per_page': 100, 'size': 'small', 'start': start, 'user': username} - activity_results2 = requests.get(activity_baseurl, params=activity_params2).json() - - for j in range(0, len(activity_results2['raw_messages'])): - # print(j,len(activity_results2['raw_messages'])) - msgdate = datetime.datetime.fromtimestamp(int(activity_results2['raw_messages'][j]['timestamp'])) - topic = activity_results2['raw_messages'][j]['topic'] - - print("\t", msgdate, topic) - - return [activity_results['total'], d] - - -class Groups: - - def __init__(self, groups): - self.count = 0 - self.role_status = "na" - for group in groups: - - # self.role_status = groups[group]['role_status'] - # self.approval = groups[group]['approval'] - print("\t", group, groups[group]['role_status'], groups[group]['approval']) - self.count += 1 - - def count_groups(self): - return self.count - - -def main(username,days): - - print("Username:", username) - fas_user = fas.person_by_username(username) - print("Human name:", fas_user['human_name']) - last_seen = datetime.datetime.strptime(fas_user['last_seen'], "%Y-%m-%d %H:%M:%S.%f%z").strftime( - "%Y-%m-%d %H:%M:%S") - print("Last seen:", last_seen) - print("Groups:") - count_groups = Groups(fas_user['group_roles']).count_groups() - print("Total groups:", count_groups) - print("Activities:") - activities = getactivitycount(username, days) - date = datetime.datetime.strptime(str(activities[1]), "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d") - print("Total activities since {}: {}".format(date, activities[0])) - - -if __name__ == '__main__': - usernametocheck = sys.argv[1] - lastactivitiessincedays = sys.argv[2] - main(usernametocheck, lastactivitiessincedays) - print("End") \ No newline at end of file diff --git a/scripts/checkstatus/myconfig.cfg.example b/scripts/checkstatus/myconfig.cfg.example deleted file mode 100644 index 1503d3e..0000000 --- a/scripts/checkstatus/myconfig.cfg.example +++ /dev/null @@ -1,3 +0,0 @@ -[FAS] -user: fasuser -pass: faspassword \ No newline at end of file