-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropbox.py
More file actions
58 lines (41 loc) · 1.58 KB
/
dropbox.py
File metadata and controls
58 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pika
import sys
import os, time
import dropbox
TOKEN = ""
def publish(self, msg):
print("Conectando con Dropbox...")
dbx = dropbox.Dropbox(TOKEN)
user = dbx.users_get_current_account()
print("Usuario " + user.name.display_name + " de " + user.country)
print("\n\nSubiendo diagrama a Dropbox...")
try:
nombre = [line.split(":")[0]]
fichero = "/" + nombre + "png"
dbx.files_upload(msg, fichero, mode=dropbox.files.WriteMode('overwrite'))
print("hi")
except dropbox.exceptions.ApiError as err:
if (err.error.is_path() and
err.error.get_path().reason.is_insufficient_space()):
sys.exit("ERROR: Cannot back up; insufficient space.")
elif err.user_message_text:
print(err.user_message_text)
sys.exit()
else:
print(err)
sys.exit()
metadata = dropbox.sharing.GetFileMetadataIndividualResult(fichero)
finalURL = metadata.preview_url
channel.basic_publish(exchange='', routing_key='linkDropbox', body=finalURL)
def callback(ch, method, properties, body) :
self.publish(body)
url = os.environ.get('CLOUDAMQP_URL', 'amqp://guest:guest@localhost:5672/%2f')
params = pika.URLParameters(url)
params.socket_timeout = 5
connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_declare(queue='graficosRelacion') # Cola de lectura
channel.queue_declare(queue='linkDropbox') # Cola de escritura
channel.basic_consume(callback, queue='graficosRelacion', no_ack=True)
channel.start_consuming()
connection.close()