Commits

Diwaker Ghimire committed e528bbb

initial commit

  • Participants

Comments (0)

Files changed (2)

+syntax: glob
+
+*.py[oc]
+"""
+Simple script to read redmine issues
+
+ver 0.1
+    return total number of new issues assigned to user
+
+:author: Diwaker Ghimire <idwaker@gmail.com>
+"""
+
+import sys
+import getpass
+import requests
+import keyring
+from keyring.backend import GnomeKeyring
+
+
+username = 'diwaker'
+service = 'http://dev.yipl.com.np:8001'
+headers = {'content-type': 'application/json'}
+
+
+keyring.set_keyring(GnomeKeyring())
+
+
+def init():
+    """
+    initialize the system by inserting password if not present already
+    """
+    password = getpass.getpass("Enter password for " + username + "(" +\
+                                    service + ") : ")
+    keyring.set_password(service, username, password)
+    return password
+
+
+def get_issues(password):
+    """
+    """
+    global headers, username, service
+    req = requests.get(service + '/issues.json?status_id=open&assigned_to_id=me',
+                auth=(username, password), headers=headers)
+    data = req.json()
+    print(data["total_count"])
+
+
+if __name__ == '__main__':
+    password = keyring.get_password(service, username)
+    if not password:
+        password = init()
+    if len(sys.argv) > 1 and sys.argv[1] == '--new-issues':
+        get_issues(password)
+    elif len(sys.argv) > 1 and sys.argv[1] == '--password':
+        init()
+        print("Password on keyring is reset")
+        sys.exit(0)
+    else:
+        print("Usage: redmind --new-issues")