Ada Young avatar Ada Young committed 2594ed9

Now we can go back by days just like in the game ^^

Comments (0)

Files changed (1)

 import sqlite3
 import optparse
 from urllib import urlencode
-from datetime import datetime
+from datetime import datetime, timedelta
 
 browser = urllib2.build_opener()
 browser.addheaders = [
 	return None
 
 def SearchLog(orgname, searchtext, fromdate=None, todate=None):
-	datenow = datetime.now().date()
+	datenow = datetime.now().date().strftime("%Y-%m-%d")
 	if fromdate is None:
-		fromdate = datenow.strftime("%Y-%m-%d")
+		fromdate = datenow
 	if todate is None:
-		todate = datenow.strftime("%Y-%m-%d")
+		todate = datenow
 
 	orgname = ValidateOrgname(orgname)
 	if orgname is None: # bail out
 		print("The supplied to date is invalid. The format is YYYY-MM-DD.")
 		exit(-1)
 
-	todate = todate + " 23:59:59" # just to include this day as well
+	todate = todate + " 23:59:59" # just to include this day as well, should probably use timedelta() here too
 
 	print("Searching [%s] logs for [%s] in the range [%s] to [%s]" % (orgname, searchtext, fromdate, todate[:-9]))
 	cursor.execute("SELECT timestamp, message FROM org_logs l join orgs o on l.orgid=o.id WHERE o.orgname=? AND l.timestamp>=datetime(?) AND l.timestamp<=datetime(?) AND l.message LIKE ? ORDER BY l.timestamp ASC", (orgname, fromdate, todate, "%" + searchtext + "%"))
 	parser = optparse.OptionParser()
 	parser.add_option('-c', '--charname', help='Your Achaea character name')
 	parser.add_option('-p', '--password', help='Your Achaea password')
-	parser.add_option('-d', '--days', help='Number of days to go back (max: 6)')
+	parser.add_option('-d', '--days', help='Number of days to go back')
 	parser.add_option('-D', '--database', help="The database file")
 
 	parser.add_option('-S', '--search', help="Search through the database",
 	fromdate = opts.fromdate
 	todate = opts.todate
 
+	days = opts.days or 0
+
+	if type(days) is not type(0):
+		print("Please specify an integer for -d parameter.")
+		parser.print_help()
+		exit(-1)
+	else:
+		days = int(days)
+
 	if opts.database is None:
 		print("You need to specify a database file\n")
 		parser.print_help()
 			exit(-1)
 		else:
 			searchtext = " ".join(args)
+			if days > 0:
+				today = datetime.now()
+				fromdate = (today - timedelta(days=days)).strftime("%Y-%m-%d")
+				todate = fromdate
 			SearchLog(orgname, searchtext, fromdate, todate)
 
 	if opts.charname is None:
 
 	charname = opts.charname
 	password = opts.password
-	days = opts.days or 0
 
 	dataset = orglogs_summary(charname, password, days)
 	dataset = process_orglogs(dataset)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.