Forráskód Böngészése

Procedure call fix ongoing (MariaDB broken)

Penta 5 éve
szülő
commit
49ef375a64

+ 27 - 1
extra/myanimebot-init-pgsql.sql

@@ -39,4 +39,30 @@ CREATE TABLE IF NOT EXISTS "t_servers" (
 
 CREATE OR REPLACE VIEW v_top         AS SELECT "user", COUNT("title") AS "total" FROM t_feeds GROUP BY "user" ORDER BY COUNT("title") DESC;
 CREATE OR REPLACE VIEW v_totalfeeds  AS SELECT COUNT(0) AS "total" FROM "t_feeds";
-CREATE OR REPLACE VIEW v_totalanimes AS SELECT COUNT(0) AS "total" from "t_animes";
+CREATE OR REPLACE VIEW v_totalanimes AS SELECT COUNT(0) AS "total" from "t_animes";
+
+CREATE OR REPLACE FUNCTION "sp_animecountperkeyword"(IN anime_var text, IN limit_var INT DEFAULT 100)
+   RETURNS TABLE("title" TEXT, "total" INT)
+   LANGUAGE 'sql'
+    
+AS $BODY$
+SELECT "title", COUNT(0) AS "total"
+   FROM "t_feeds"
+   WHERE LOWER("title") LIKE '%' || LOWER(anime_var) || '%'
+   GROUP BY "title"
+   ORDER BY COUNT(id) DESC
+   LIMIT limit_var;
+$BODY$;
+
+CREATE OR REPLACE FUNCTION "sp_usersperkeyword"(IN anime_var text, IN limit_var INT DEFAULT 100)
+   RETURNS TABLE("user" TEXT, "total" INT)
+   LANGUAGE 'sql'
+   
+AS $BODY$
+SELECT "user", COUNT("title") AS "total"
+   FROM "t_feeds"
+   WHERE LOWER("title") LIKE '%' || LOWER(anime_var) || '%'
+   GROUP BY "user"
+   ORDER BY COUNT("title") DESC
+   LIMIT limit_var;
+$BODY$;

+ 0 - 1
myanimebot.example.conf

@@ -28,7 +28,6 @@ postgresql.host = $DB_HOST
 postgresql.user = $DB_USER
 postgresql.password = $DB_PASSWORD
 postgresql.name = $DB_NAME
-postgresql.schema = public
 postgresql.port = 5432
 
 # timezone (should be the same as the DB and your Linux system)

+ 1 - 1
myanimebot/anilist.py

@@ -375,7 +375,7 @@ async def background_check_feed(asyncioloop):
         try:
             await check_new_activities()
         except Exception as e:
-            globals.logger.exception('Error while fetching Anilist feeds : ({})'.format(e))
+            globals.logger.error('Error while fetching Anilist feeds : ({})'.format(e))
 
         await asyncio.sleep(globals.ANILIST_SECONDS_BETWEEN_FETCHES)
 

+ 12 - 15
myanimebot/commands.py

@@ -389,21 +389,18 @@ async def top_cmd(words, channel):
         
         try:
             cursor = database.create_cursor()
-            cursor.callproc('sp_UsersPerKeyword', [str(keyword), '20'])
-            for result in cursor.stored_results():
-                data = result.fetchone()
-                
-                if data is None: await message.channel.send("It seems that there is no statistics for the keyword **" + keyword + "**.")
-                else:
-                    topKeyText = "**__Here is the statistics for the keyword " + keyword + ":__**\n\n"
-                    
-                    while data is not None:
-                        topKeyText += " - " + str(data[0]) + ": " + str(data[1]) + "\n"
-                            
-                        data = result.fetchone()
-                        
-                    await channel.send(topKeyText)
-                
+            cursor.callproc('sp_UsersPerKeyword', [str(keyword), 20])
+            result = cursor.fetchall();
+            topKeyText = ""
+
+            for data in result:
+                    topKeyText += " - {}: {}\n".format(data[0], data[1])
+
+            if (topKeyText != ""):
+                await channel.send("**__Here is the statistics for the keyword {}:__**\n\n{}".format(keyword, topKeyText))
+            else:
+                await channel.send("It seems that there is no statistics for the keyword **{}**.".format(keyword))
+
             cursor.close()
         except Exception as e:
             globals.logger.warning("An error occured while displaying the global top for keyword '" + keyword + "': " + str(e))

+ 1 - 1
myanimebot/database.py

@@ -32,4 +32,4 @@ def insert_feed_db(feed, service : str):
 						 feed.get_status_str(),
 						 service))
 	
-	globals.conn.commit()
+	globals.conn.commit()