Переглянути джерело

Using Rocket.Chat fields instead of attachments

Nikola Kotur 3 роки тому
батько
коміт
9d8ac6d382
1 змінених файлів з 8 додано та 3 видалено
  1. 8 3
      src/ynrc/main.py

+ 8 - 3
src/ynrc/main.py

@@ -134,19 +134,24 @@ def post_to_rocketchat(hook, avatar, ynab):
 
     post_data = {
         "alias": "YNAB",
-        "text": 'YNAB report for week of %s (from %s)' % (today.strftime('%Y-%W'), week_ago.strftime('%a %Y-%m-%d')),
+        "text": 'Report for week of %s (from %s)' % (today.strftime('%Y-%W'), week_ago.strftime('%a %Y-%m-%d')),
         "attachments": [
         ],
     }
     if avatar:
         post_data['avatar'] = avatar
 
+    fields = []
     for spending in ynab:
         spending_name, spending_amount = spending
-        post_data['attachments'].append({
+        fields.append({
             "title": spending_name,
-            "text": spending_amount,
+            "value": spending_amount,
         })
+    post_data['attachments'] = [{
+        'title': 'Top 10 categories spent',
+        'fields': fields,
+    }]
 
     result = requests.post(
         hook,