bin/crashreportScraper.py |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

New commits:
commit 970f03cb9ed68d249fe04cff7d4aa15b0f2c6c35
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jun 16 13:16:13 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jun 16 13:26:36 2022 +0200

    crashreportScraper: use argparse to parse the arguments
    
    Change-Id: Idc1d32683c5113042fe4e7ec97357b6d76c5217e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135973
    Tested-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/bin/crashreportScraper.py b/bin/crashreportScraper.py
index aec3e5e9cffb..513f5ec7b75d 100755
--- a/bin/crashreportScraper.py
+++ b/bin/crashreportScraper.py
@@ -8,8 +8,9 @@
 
 # Use this script to retrieve information from 
https://crashreport.libreoffice.org
 # about a specific version of LibreOffice
-# Usage sample: ./crashreportScraper.py 7.2.0.4
+# Usage sample: ./crashreportScraper.py --version 7.2.0.4 --repository 
/path/to/libreoffice/repository/
 
+import argparse
 import requests
 from bs4 import BeautifulSoup
 import sys
@@ -160,17 +161,20 @@ def parse_details_and_get_info(url, gitRepo):
 
 if __name__ == '__main__':
 
-    version = sys.argv[1]
+    parser = argparse.ArgumentParser()
 
-    crashes = parse_version_url(
-            "https://crashreport.libreoffice.org/stats/version/"; + version + 
"?limit=1000&days=30")
+    parser.add_argument('--version', action='store', dest="version", 
required=True)
+    parser.add_argument('--repository', action="store", dest="repository", 
required=True)
+
+    args = parser.parse_args()
 
-    gitRepo = os.path.dirname(os.path.realpath(__file__)) + "/../"
+    crashes = parse_version_url(
+            "https://crashreport.libreoffice.org/stats/version/"; + 
args.version + "?limit=1000&days=30")
 
-    print(str(len(crashes)) + " crash reports in version " + version)
+    print(str(len(crashes)) + " crash reports in version " + args.version)
 
     crashesInFile = []
-    fileName = "crashes_" + version.replace(".", "_") + ".csv"
+    fileName = "crashes_" + args.version.replace(".", "_") + ".csv"
     print("Using " + fileName)
 
     bInsertHeader = False
@@ -196,7 +200,7 @@ if __name__ == '__main__':
                     crashCount, crashID, crashVersion, crashOS = 
parse_reports_and_get_most_recent_report_from_last_page(
                             
"https://crashreport.libreoffice.org/stats/signature/"; + k)
                     crashReason, crashStack, codeLine = 
parse_details_and_get_info(
-                            
"https://crashreport.libreoffice.org/stats/crash_details/"; + crashID, gitRepo)
+                            
"https://crashreport.libreoffice.org/stats/crash_details/"; + crashID, 
args.repository)
                     line = '\t'.join([k, str(crashCount), lDate[1], lDate[2],
                             crashID, crashVersion, crashReason, crashOS, 
crashStack, codeLine, '\n'])
                     f.write(line)

Reply via email to