On Sat, Sep 28, 2024 at 12:11 PM Matthias Seidel <matthias.sei...@hamburg.de>
wrote:

> Hi All,
>
> Until now I could run the python scripts here:
>
> https://svn.apache.org/repos/asf/openoffice/devtools/aoo-stats/
>
> because I still was able to install Python 2 on Ubuntu 22.04.
>
> After upgrading to Ubuntu 24.04 I cannot do this anymore. Running the
> scripts with Python 3 gives me errors.
>
> Could someone with Python knowledge have a look at those scripts, please?
>
> Regards,
>
>     Matthias
>
>
Hi

You haven't really given examples of how to run those scripts, but I think
I fixed one of them.

I just had to:
* Change the urllib import to urllib.request:
-import urllib
+import urllib.request
* Delete the unused and now invalid urllib.urlencode import:
-from urllib import urlencode
* Change urllib.urlopen() to urllib.request.urlopen():
-            conn = urllib.urlopen(url)
+            conn = urllib.request.urlopen(url)
* Change every print x to print(x).

The complete patch is attached so you can test it with Python 3. I am not
sure how to run it or what output it's supposed to give.

Regards
Damjan
Index: get-aoo-stats.py
===================================================================
--- get-aoo-stats.py	(revision 1921006)
+++ get-aoo-stats.py	(working copy)
@@ -26,14 +26,12 @@
 # is written to stdout.
 
 
-import urllib
+import urllib.request
 import json
 import sys
 import datetime
 import time
 
-from urllib import urlencode
-
 def getSourceForgeStats(download, startDate, endDate):
 
     url = download + "/stats/json?start_date=" + startDate + "&" "end_date=" + endDate
@@ -42,7 +40,7 @@
 
     while attempts < 3:
         try:
-            conn = urllib.urlopen(url)
+            conn = urllib.request.urlopen(url)
             data = conn.read()
 
             return data
@@ -49,15 +47,15 @@
 
         except:
             attempts += 1
-            print "error " + str(attempts)
+            print("error " + str(attempts))
 
     return ""
 
 def printSyntax():
-    print "syntax: python get-aoo-stats.py <urls.lst> <iso-date> [<iso-date>]"
-    print "where <urls.lst> is a list of files URLs to gather stats on,"
-    print "and <iso-date> is a date of interest, in YYYY-MM-DD format."
-    print "If two dates are given this expresses a range of dates."
+    print("syntax: python get-aoo-stats.py <urls.lst> <iso-date> [<iso-date>]")
+    print("where <urls.lst> is a list of files URLs to gather stats on,")
+    print("and <iso-date> is a date of interest, in YYYY-MM-DD format.")
+    print("If two dates are given this expresses a range of dates.")
 
 
 if len(sys.argv) == 2:
@@ -77,6 +75,7 @@
 downloads = [line.strip() for line in open(sys.argv[1])]
 
 count = 0
+data = {}
 
 for download in downloads :
 
@@ -89,11 +88,11 @@
 
     day_count = data["total"]
 
-    print download + "," + str(day_count)
+    print(download + "," + str(day_count))
 
     count = count + day_count
 
-print "date range: " + startDate + " - " + endDate
-print "stats_updated: " + data["stats_updated"]
-print "count: " + str(count)
+print("date range: " + startDate + " - " + endDate)
+print("stats_updated: " + data["stats_updated"])
+print("count: " + str(count))
 
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org

Reply via email to