-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateTweet.js
More file actions
149 lines (131 loc) · 3.63 KB
/
createTweet.js
File metadata and controls
149 lines (131 loc) · 3.63 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require('dotenv').config()
const tkey = process.env.tkey
const tsecret = process.env.tsecret
const atoken = process.env.atoken
const asecret = process.env.asecret
const Twit = require('twit')
const db = require('./models')
let T = new Twit({
consumer_key: tkey,
consumer_secret: tsecret,
access_token: atoken,
access_token_secret: asecret,
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
strictSSL: true, // optional - requires SSL certificates to be valid.
})
let testObj = {
"_id" : "5d3651584021fc2b0e16afc6",
"name" : "Barbara Lee",
"twitter" : "@RepBarbaraLee",
"__v" : 0,
"v_2010_h_1" : "Y",
"v_2010_h_2" : "Y",
"v_2010_h_3" : "voteless",
"v_2010_s_1" : null,
"v_2015_b_1" : "Y",
"v_2019_h_1" : "Y",
"v_2019_s_1" : null,
"chamber" : "House",
"district" : "13",
"state" : "CA",
"party" : "D"
}
let votesSeq = {
'v_2010_h_1': {
year: '2010',
text: 'House RC#491'
},
'v_2010_h_2': {
year: '2010',
text: 'House RC#550'
},
'v_2010_h_3': {
year: '2010',
text: 'House RC#664'
},
'v_2010_s_1': {
year: '2010',
text: 'House RC#269'
},
'v_2015_b_1': {
year: '2015',
text: 'HR1786 Sponsor'
},
'v_2019_h_1': {
year: '2019',
text: 'House RC#474'
},
'v_2019_s_1': {
year: '2019',
text: 'Senate RC#224'
}
}
let chooseEmoji = {
'Y': '✅',
'N': '❌',
'voteless': '❓'
}
let votesIter = [
'v_2010_h_1',
'v_2010_h_2',
'v_2010_h_3',
'v_2010_s_1',
'v_2015_b_1',
'v_2019_h_1',
'v_2019_s_1'
]
module.exports ={
tweet: function createTweet(id, dataObj) {
// test case commented out below
// let at = "@DidTheyForget\n"
let at = dataObj['twitter']+"\n"
let intro = `${dataObj['chamber'] === 'Senate' ? 'Sen. ' : 'Rep. '}${dataObj['name']} (${dataObj['party']}) ${dataObj['state']}${dataObj['district'] ? '-' + dataObj['district'] : ''}\n\nRecord on 9/11 First Responder bills:`
let votes = []
votesIter.forEach((rollCall, i) => {
if (dataObj[rollCall]) {
votes.push(rollCall)
}
})
let meat = ''
votes.forEach((vote, i) => {
meat = meat + `\n${chooseEmoji[dataObj[vote]]} ${votesSeq[vote].year} ${votesSeq[vote].text} - ${dataObj[vote]}`
})
let outro = '\n\n#NeverForget\n#DidTheyForget'
let full = at + intro + meat + outro
let almostFull = intro + meat + outro
function createTweet(dataObj) {
let intro = `${dataObj['twitter']}\n${dataObj['chamber'] === 'Senate' ? 'Sen. ' : 'Rep. '}${dataObj['name']} (${dataObj['party']}) ${dataObj['state']}${dataObj['district'] ? '-' + dataObj['district'] : ''} support record for 9/11 first responder bills:`
// post tweet
// T.post('statuses/update', {
// in_reply_to_status_id: id,
// status: full,
// }, function(err, data, response) {
// console.log(data)
// //retweet this?
// })
// CONSOLE LOG TWEET
console.log("\n\n\n\n\n\nTWEET:\n-----------------------------------------------\n"+full+"\n\n\n\n")
// retweet their tweet with the voting record added
// techincally we are posting a new tweet, and linking to their tweet
// because there is no retweet with comment in the twitter api
let full = intro + meat + outro
console.log(full)
if (full.length > 260) {
console.log(full.length)
}
console.log()
// T.post('statuses/update', {
// attachment_url: 'https://twitter.com/'+dataObj['twitter'].substr(1)+'/status/' + id,
// status: almostFull,
// }, function(err, data, response) {
// console.log(data)
// })
}
}
db.Reps.find({})
.then(reps => {
reps.forEach((rep, i) => {
createTweet(rep)
console.log(i);
})
})