jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/395697 )

Change subject: [IMPR] some improvements for data_ingestion.py
......................................................................

[IMPR] some improvements for data_ingestion.py

- use try..else instead of continue inside exception
- use contextlib.closing to close a file

Change-Id: Ic2c0b043d23065b95d34d9034eb27e3a3822f069
---
M scripts/data_ingestion.py
1 file changed, 11 insertions(+), 16 deletions(-)

Approvals:
  Dalba: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py
index a6628c1..48e98b4 100755
--- a/scripts/data_ingestion.py
+++ b/scripts/data_ingestion.py
@@ -285,26 +285,21 @@

         filename = os.path.join(csv_dir, configuration['csvFile'])
         try:
-
             f = codecs.open(filename, 'r', configuration['csvEncoding'])
         except (IOError, OSError) as e:
             pywikibot.error('%s could not be opened: %s' % (filename, e))
-            continue
+        else:
+            with f:
+                files = CSVReader(f, urlcolumn='url',
+                                  site=config_page.site,
+                                  dialect=configuration['csvDialect'],
+                                  delimiter=str(configuration['csvDelimiter']))

-        try:
-            files = CSVReader(f, urlcolumn='url',
-                              site=config_page.site,
-                              dialect=configuration['csvDialect'],
-                              delimiter=str(configuration['csvDelimiter']))
-
-            bot = DataIngestionBot(files,
-                                   configuration['titleFormat'],
-                                   configuration['formattingTemplate'],
-                                   site=None)
-
-            bot.run()
-        finally:
-            f.close()
+                bot = DataIngestionBot(files,
+                                       configuration['titleFormat'],
+                                       configuration['formattingTemplate'],
+                                       site=None)
+                bot.run()


 if __name__ == "__main__":

--
To view, visit https://gerrit.wikimedia.org/r/395697
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic2c0b043d23065b95d34d9034eb27e3a3822f069
Gerrit-Change-Number: 395697
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <i...@gno.de>
Gerrit-Reviewer: Dalba <dalba.w...@gmail.com>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
Pywikibot-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to