-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitcoin.gs
133 lines (107 loc) · 4.12 KB
/
gitcoin.gs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function version() {
version = "0.0.9"
Logger.log("version: "+ version)
return version
}
function insertGrantList() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]
var newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1]
var selection = sheet.getSelection()
var activeRange = selection.getActiveRange()
var list = activeRange.getValues()
for (const ele of list) {
var grantId = ele[0].split("/")[4]
var grant = getGitcoinById(grantId)
var lastRow = newSheet.getLastRow();
var lastCell = newSheet.getRange(lastRow, 1)
lastCell.offset(1, 0).setValue(grantId)
lastCell.offset(1, 1).setValue(grant['title'])
lastCell.offset(1, 2).setValue(grant['tags'].join(','))
lastCell.offset(1, 3).setValue(grant['website'])
lastCell.offset(1, 4).setValue(grant['walletAddress'])
lastCell.offset(1, 5).setValue(grant['twitter'])
lastCell.offset(1, 6).setValue(grant['region'])
lastCell.offset(1, 7).setValue(grant['lastUpdated'])
lastCell.offset(1, 8).setValue(grant['fundsReceivedFromAllContributors'])
lastCell.offset(1, 9).setValue(grant['members'].join(","))
lastCell.offset(1, 10).setValue(grant['github'])
lastCell.offset(1, 11).setValue(grant['introduction'])
}
}
function insertGrant() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("")
var newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("")
if (sheet != null) {
var currCell = sheet.getCurrentCell()
var content = currCell.getValue()
var grantId = content.split("/")[4]
var grant = getGitcoinById(grantId)
var lastRow = newSheet.getLastRow();
var lastCell = newSheet.getRange(lastRow, 1)
lastCell.offset(1, 0).setValue(grantId)
lastCell.offset(1, 1).setValue(grant['title'])
lastCell.offset(1, 2).setValue(grant['tags'].join(','))
lastCell.offset(1, 3).setValue(grant['website'])
lastCell.offset(1, 4).setValue(grant['walletAddress'])
lastCell.offset(1, 5).setValue(grant['twitter'])
lastCell.offset(1, 6).setValue(grant['region'])
lastCell.offset(1, 7).setValue(grant['lastUpdated'])
lastCell.offset(1, 8).setValue(grant['fundsReceivedFromAllContributors'])
lastCell.offset(1, 9).setValue(grant['members'].join(","))
lastCell.offset(1, 10).setValue(grant['github'])
// lastCell.offset(1, 11).setValue(grant['introduction'])
}
}
function getGitcoinById(grantId) {
// https://gitcoin.co/grants/v1/api/grant/187/
var url = "https://gitcoin.co/grants/v1/api/grant/" + grantId + "/";
var options = {
'method': 'get',
'contentType': 'application/json',
muteHttpExceptions: true,
};
var resp = UrlFetchApp.fetch(url, options);
Logger.log(resp.getContentText());
var obj = JSON.parse(resp.getContentText());
var status = obj['status'];
var newGrant = {}
if (200 == status) {
var grant = obj['grants']
var title = grant['title']
var _tags = grant['grant_tags']
var tags = []
for (const item of _tags) {
tags.push(item.fields['name'])
}
var website = grant['reference_url']
var walletAddress = grant['admin_address']
var twitter = grant['twitter_handle_1']
var region = null
if (grant['region'] != null) {
region = grant['region']['label']
}
var lastUpdated = grant['last_update']
var fundsReceivedFromAllContributors = grant['funding_info']
var _members = grant['team_members']
var members = []
for (const item of _members) {
members.push(item['fields']['handle'])
}
var githubUrl = grant['github_project_url']
var introduction = grant['description']
newGrant['title'] = title
newGrant['website'] = website
newGrant['tags'] = tags
newGrant['members'] = members
newGrant['walletAddress'] = walletAddress
newGrant['twitter'] = "https://twitter.com/" + twitter
newGrant['region'] = region
newGrant['lastUpdated'] = lastUpdated
newGrant['fundsReceivedFromAllContributors'] = fundsReceivedFromAllContributors
newGrant['github'] = githubUrl
newGrant['introduction'] = introduction
} else {
Logger.log("http status:" + status);
}
return newGrant
}