:art: Qiniu Once

huangqimin001 3 lat temu
rodzic
commit
9dd1919f18
1 zmienionych plików z 23 dodań i 0 usunięć
  1. 23 0
      commands/management/commands/qiniuonce.py

+ 23 - 0
commands/management/commands/qiniuonce.py

@@ -0,0 +1,23 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import os
4
+
5
+from django_six import CompatibilityBaseCommand
6
+
7
+from utils.qiniucdn import upload_file_path
8
+
9
+
10
+class Command(CompatibilityBaseCommand):
11
+    def handle(self, *args, **options):
12
+
13
+        files = os.listdir('media/file')
14
+
15
+        for file in files:
16
+            print(file)
17
+            try:
18
+                file_path = 'media/file/{}'.format(file)
19
+                if os.path.exists(file_path):
20
+                    upload_file_path(file_path, key=file, bucket='tamron')
21
+                    os.remove(file_path)
22
+            except Exception:
23
+                pass