Skip to content
This repository
Browse code

+ check if media is already uploaded

  • Loading branch information...
commit a57e047f2af898e59d0ee181601fa42963030bbd 1 parent df5476f
Nils Dagsson Moskopp authored July 23, 2012

Showing 1 changed file with 24 additions and 0 deletions. Show diff stats Hide diff stats

  1. 24  oa-put
24  oa-put
@@ -50,6 +50,24 @@ if action == 'upload-media':
50 50
     wiki = wikitools.wiki.Wiki(config.api_url)
51 51
     wiki.login(username=config.username, password=config.password)
52 52
 
  53
+    def is_uploaded(material):
  54
+        params = {
  55
+            'action': 'query',
  56
+            'list': 'search',
  57
+            'srwhat': 'text',
  58
+            'srnamespace': '6',  # media files
  59
+            'srsearch': '"%s"+"%s"+"%s"' % (
  60
+                material.article.title,
  61
+                material.label,
  62
+                material.caption.split('.')[0]
  63
+            )
  64
+        }
  65
+        request = wikitools.api.APIRequest(wiki, params)
  66
+        result = request.query()
  67
+        if result[u'query'][u'searchinfo'][u'totalhits'] > 0:
  68
+            return True
  69
+        return False
  70
+
53 71
     materials = SupplementaryMaterial.query.filter_by(
54 72
         converted=True,
55 73
         uploaded=False
@@ -60,7 +78,13 @@ if action == 'upload-media':
60 78
         media_refined_path = path.join(media_refined_directory, filename)
61 79
 
62 80
         if (path.getsize(media_refined_path) == 0):
  81
+            material.converted=False
  82
+            continue
  83
+
  84
+        if is_uploaded(material):
  85
+            material.uploaded=True
63 86
             continue
  87
+
64 88
         wiki_file = wikitools.wikifile.File(wiki=wiki, title=filename)
65 89
         wiki_file.upload(
66 90
             fileobj = open(media_refined_path, 'r'),

0 notes on commit a57e047

Please sign in to comment.
Something went wrong with that request. Please try again.