forked from axeleroy/untoitpourcaramel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrello_module.py
More file actions
75 lines (58 loc) · 2.31 KB
/
trello_module.py
File metadata and controls
75 lines (58 loc) · 2.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
from trello import TrelloClient
from models import Annonce
from ast import literal_eval
def get_board():
'''
Retourne la liste Trello indiquée dans trello.ini
'''
# Chargement des paramètres et identifiants Trello depuis le fichier JSON
with open("trello.json") as parameters_data:
config = json.load(parameters_data)
trello = TrelloClient(
api_key=config['ApiKey'],
api_secret=config['ApiSecret'],
token=config['Token'],
token_secret=config['TokenSecret']
)
for b in trello.list_boards():
if b.name == config['BoardName']:
return b
print("Board " + config['BoardName'] + " not found.")
exit()
def get_list(site):
board = get_board()
for l in board.all_lists():
if l.name == site:
return l
# Liste pas trouvée, on la crée
return board.add_list(site)
def post():
'''
Poste les annonces sur Trello
'''
posted = 0
for annonce in Annonce.select().where(Annonce.posted2trello == False).order_by(Annonce.site.asc()):
title = "%s de %sm² à %s @ %s€" % (annonce.title, annonce.surface, annonce.city, annonce.price)
description = "Créé le : %s\n\n" \
"%s pièces, %s chambre(s)\n" \
"Charges : %s\n" \
"Tel : %s\n\n" % \
(annonce.created.strftime("%a %d %b %Y %H:%M:%S"), annonce.rooms, annonce.bedrooms, annonce.charges,
annonce.telephone)
if annonce.description is not None:
description += ">%s" % annonce.description.replace("\n", "\n>")
card = get_list(annonce.site).add_card(title, desc=description)
# On s'assure que ce soit bien un tableau
if annonce.picture is not None and annonce.picture.startswith("["):
# Conversion de la chaîne de caractère représentant le tableau d'images en tableau
for picture in literal_eval(annonce.picture):
card.attach(url=picture)
# Il n'y a qu'une photo
elif annonce.picture is not None and annonce.picture.startswith("http"):
card.attach(url=annonce.picture)
card.attach(url=annonce.link)
annonce.posted2trello = True
annonce.save()
posted += 1
return posted