Read
Tags: #canny #product
Author: Martin Donadieu

Enter credentials

Input

Import librairies

1
import requests
2
import json
3
import pandas as pd
Copied!

API key

1
canny_api = "CANNY_API_KEY" # api key of canny
Copied!

Model

Connecting to canny

1
class canny:
2
def __init__(self,api_key):
3
self.api_key = api_key
4
5
def read(self):
6
canny_api = self.api_key
7
response = requests.get("https://canny.io/api/v1/posts/list")
8
api_key = {
9
"apiKey":canny_api
10
}
11
board_id = {
12
"id":""
13
}
14
limit = {
15
"limit":"100"
16
}
17
data = {**api_key, **board_id, **limit}
18
response = requests.post("https://canny.io/api/v1/posts/list",data)
19
post_details = response.json()
20
pd.set_option('mode.chained_assignment', None)
21
dd = post_details['posts']
22
df = pd.DataFrame(columns = dd[0].keys())
23
for i in range(len(dd)):
24
df = df.append(dd[i], ignore_index=True)
25
df = df.rename(columns={'details': 'POST_DETAIL', 'status': 'STATUS', 'title': 'POST_NAME','board': 'BOARD','category': 'CATEGORY','id': 'BOARD_ID'})
26
board = []
27
category = []
28
tags = []
29
eta = []
30
created = []
31
for i in range(len(df)):
32
board.append(df['BOARD'][i]['name'])
33
created.append(df['BOARD'][i]['created'])
34
if not df['CATEGORY'][i]:
35
category.append('Not assigned')
36
else:
37
category.append(df['CATEGORY'][i]['name'])
38
if not df['tags'][i]:
39
tags.append('Not assigned')
40
else:
41
tags.append(df['tags'][i][0]['name'])
42
if not df['eta'][i]:
43
eta.append('Not assigned')
44
else:
45
eta.append(df['eta'][i])
46
df1 = df[['POST_NAME','POST_DETAIL','STATUS','BOARD_ID']]
47
df1['BOARD'] = board
48
df1['CREATED'] = created
49
df1['ETA'] = eta
50
df1['CATEGORY'] = category
51
df1['TAGS'] = tags
52
return df1
Copied!

Post Retrieve

1
canny(canny_api).read()
Copied!

Output

Save as csv

1
canny(canny_api).read().to_csv('naas_canny.csv')
Copied!
Copy link
Edit on GitHub