mirror of
				https://github.com/lubuntu-team/lugito.git
				synced 2025-10-31 16:44:11 +00:00 
			
		
		
		
	Use the logging library instead of print statements.
Summary: Convert Lugito to use the logging library rather than print statements. Test Plan: I tested the bot with a random freenode channel - it works without any issues. Differential Revision: https://phab.lubuntu.me/D2
This commit is contained in:
		
							parent
							
								
									adcfa174e3
								
							
						
					
					
						commit
						329a0293f3
					
				
							
								
								
									
										30
									
								
								lugito
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								lugito
									
									
									
									
									
								
							| @ -5,6 +5,7 @@ import hmac | |||||||
| import json | import json | ||||||
| import socket | import socket | ||||||
| import threading | import threading | ||||||
|  | import logging | ||||||
| from flask import Flask, request | from flask import Flask, request | ||||||
| from pprint import pprint | from pprint import pprint | ||||||
| from hashlib import sha256 | from hashlib import sha256 | ||||||
| @ -19,6 +20,9 @@ server = "irc.freenode.net" | |||||||
| port = 6667 | port = 6667 | ||||||
| channel = "#lubuntu-devel" | channel = "#lubuntu-devel" | ||||||
| 
 | 
 | ||||||
|  | logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG) | ||||||
|  | logger = logging.getLogger(__name__) | ||||||
|  | 
 | ||||||
| app = Flask(__name__) | app = Flask(__name__) | ||||||
| 
 | 
 | ||||||
| def connecttoirc(): | def connecttoirc(): | ||||||
| @ -47,6 +51,7 @@ def connecttoirc(): | |||||||
| 
 | 
 | ||||||
|         if "366" in response: |         if "366" in response: | ||||||
|             setup = True |             setup = True | ||||||
|  |     logger.info("Successfully connected to the IRC server.") | ||||||
| 
 | 
 | ||||||
| def isnewtask(task): | def isnewtask(task): | ||||||
|     modified = None |     modified = None | ||||||
| @ -76,7 +81,7 @@ def ircmessage(objectstr, who, body, link): | |||||||
|     # e.g. https://phab.lubuntu.me/T40#779 |     # e.g. https://phab.lubuntu.me/T40#779 | ||||||
|     message = message + "\x032" + link + "\x03" |     message = message + "\x032" + link + "\x03" | ||||||
|     # Make sure we can debug this if it goes haywire |     # Make sure we can debug this if it goes haywire | ||||||
|     print(message) |     logger.debug(message) | ||||||
|     # Sleep for a second, so when we have a bunch of messages we have a buffer |     # Sleep for a second, so when we have a bunch of messages we have a buffer | ||||||
|     sleep(1) |     sleep(1) | ||||||
|     # Aaaaand, send it off! |     # Aaaaand, send it off! | ||||||
| @ -141,11 +146,11 @@ def listenirc(): | |||||||
|     while True: |     while True: | ||||||
|         ircmsg = conn.recv(512) |         ircmsg = conn.recv(512) | ||||||
|         if len(ircmsg) == 0: |         if len(ircmsg) == 0: | ||||||
|             print("Connection lost, reconnecting!") |             logger.warn("Connection lost, reconnecting!") | ||||||
|             connecttoirc() |             connecttoirc() | ||||||
|             continue |             continue | ||||||
|         ircmsg = ircmsg.decode("UTF-8").strip('\n\r') |         ircmsg = ircmsg.decode("UTF-8").strip('\n\r') | ||||||
|         print(ircmsg) |         logger.debug(ircmsg) | ||||||
|         if ircmsg.find("PING :") != -1: |         if ircmsg.find("PING :") != -1: | ||||||
|             conn.send(bytes("PONG :pingis\n", "UTF-8")) |             conn.send(bytes("PONG :pingis\n", "UTF-8")) | ||||||
|         elif ircmsg.find(" :" + username + ": info") != -1: |         elif ircmsg.find(" :" + username + ": info") != -1: | ||||||
| @ -160,8 +165,7 @@ def main(): | |||||||
|     # We MUST ensure that the request came from Phab. |     # We MUST ensure that the request came from Phab. | ||||||
|     if hash.hexdigest() == request.headers["X-Phabricator-Webhook-Signature"]: |     if hash.hexdigest() == request.headers["X-Phabricator-Webhook-Signature"]: | ||||||
|         data = json.loads(data) |         data = json.loads(data) | ||||||
|         print(data) |         logger.debug(data) | ||||||
|         print |  | ||||||
| 
 | 
 | ||||||
|         exists = True |         exists = True | ||||||
|         try: |         try: | ||||||
| @ -175,15 +179,15 @@ def main(): | |||||||
|             exists = False |             exists = False | ||||||
| 
 | 
 | ||||||
|         if exists: |         if exists: | ||||||
|             print("Object exists, checking to see if it's a task or a commit.") |             logger.debug("Object exists, checking to see if it's a task or a commit.") | ||||||
| 
 | 
 | ||||||
|             if data["object"]["type"] == "TASK": |             if data["object"]["type"] == "TASK": | ||||||
|                 print("This is a task. Checking if it's new.") |                 logger.debug("This is a task. Checking if it's new.") | ||||||
|                 newtask = isnewtask(search) |                 newtask = isnewtask(search) | ||||||
|                 if newtask: |                 if newtask: | ||||||
|                     print("Yes, it's a new task.") |                     logger.debug("Yes, it's a new task.") | ||||||
|                 else: |                 else: | ||||||
|                     print("No, it's not a new task.") |                     logger.debug("No, it's not a new task.") | ||||||
| 
 | 
 | ||||||
|                 # If it's not a new task, let's see if it's a comment, and if it's just an edit. |                 # If it's not a new task, let's see if it's a comment, and if it's just an edit. | ||||||
|                 comment = None |                 comment = None | ||||||
| @ -197,14 +201,14 @@ def main(): | |||||||
|                         datemodified = task["dateModified"] |                         datemodified = task["dateModified"] | ||||||
|                         # All comments within ten seconds of the request are fair game. |                         # All comments within ten seconds of the request are fair game. | ||||||
|                         if datemodified >= (dataepoch - 10) and datemodified <= (dataepoch + 10) and task["comments"] != []: |                         if datemodified >= (dataepoch - 10) and datemodified <= (dataepoch + 10) and task["comments"] != []: | ||||||
|                             print("It's a comment, yes.") |                             logger.debug("It's a comment, yes.") | ||||||
|                             comment = True |                             comment = True | ||||||
|                             commentid = task["id"] |                             commentid = task["id"] | ||||||
|                             if datemodified != task["dateCreated"]: |                             if datemodified != task["dateCreated"]: | ||||||
|                                 print("The comment was edited.") |                                 logger.debug("The comment was edited.") | ||||||
|                                 edited = True |                                 edited = True | ||||||
|                             else: |                             else: | ||||||
|                                 print("The comment was NOT edited.") |                                 logger.debug("The comment was NOT edited.") | ||||||
|                                 edited = False |                                 edited = False | ||||||
|                             break |                             break | ||||||
|                         else: |                         else: | ||||||
| @ -231,7 +235,7 @@ def main(): | |||||||
|                     ircmessage(objectstr, who, body, link) |                     ircmessage(objectstr, who, body, link) | ||||||
| 
 | 
 | ||||||
|             elif data["object"]["type"] == "CMIT": |             elif data["object"]["type"] == "CMIT": | ||||||
|                 print("It's a commit!") |                 logger.debug("It's a commit!") | ||||||
|                 commitphid = data["object"]["phid"] |                 commitphid = data["object"]["phid"] | ||||||
| 
 | 
 | ||||||
|                 objectstr = phab.phid.query(phids=[commitphid])[commitphid]["fullName"] |                 objectstr = phab.phid.query(phids=[commitphid])[commitphid]["fullName"] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user