-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
randymcmillan.twitter.py
executable file
·243 lines (200 loc) · 6.76 KB
/
randymcmillan.twitter.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python3
# https://github.com/geduldig/TwitterAPI
import sys
import os
import requests
import shutil
# import importlib
# from importlib.resources import read_text
import time
import blockcypher
import hashlib
# import pyjq
# os.environ['PYTHONPATH']
sys.path.append('.')
sys.path.append("/usr/local/lib/python3.10/site-packages")
from TwitterAPI import TwitterAPI
def moveBlockTime():
try:
shutil.move(os.getcwd()+"/BLOCK_TIME", os.getcwd()+"/OLD_BLOCK_TIME")
except:
f = open("BLOCK_TIME", "w")
f.write("" + 0 + "\n")
f.close()
def getMillis():
global millis
millis = int(round(time.time() * 1000))
return millis
def getSeconds():
global seconds
seconds = int(round(time.time()))
return seconds
def blockTime():
try:
global block_time
block_time = blockcypher.get_latest_block_height(coin_symbol='btc')
global block_height
block_height = repr(block_time)
f = open("BLOCK_TIME", "w")
f.write("" + block_height + "\n")
f.close()
return block_time
except:
return 0
pass
def BTC_UNIX_TIME():
global btc_unix_time
btc_unix_time = str(blockTime())+":"+str(getSeconds())
return btc_unix_time
def WEEBLE_WOBBLE():
return str(WEEBLE())+":"+str(WOBBLE())
def WEEBLE():
global weeble
global wobble
global w_seconds
global w_block_time
w_seconds = getSeconds()
w_block_time = blockTime()
weeble = w_seconds / w_block_time
print("weeble="+str(weeble))
return weeble
def WOBBLE():
"""globally initialized in WEEBLE"""
wobble = w_seconds % w_block_time
print("wobble="+str(wobble))
return wobble
def getData(filename):
f = open(filename)
global data
data = f.read()
f.close()
return data
def tweetBlockTime(block_time):
if (block_time != obt):
# r = api.request('statuses/update', {'status': block_time+":"+getSeconds })
r = api.request('statuses/update', {'status': BTC_UNIX_TIME() })
# print(BTC_UNIX_TIME)
# exit()
if (r.status_code == 200):
print('api.request SUCCESS')
else:
print('api.request FAILURE')
else:
print('tweetBlockTime() FAILURE')
def getMempoolAPI(url,DATA):
# print(url)
with open(DATA, 'wb') as f:
r = requests.get(url, stream=True)
f.writelines(r.iter_content(1024))
response = getData(DATA)
# print(getData(DATA))
# print(response)
def searchBitcoin():
r = api.request('search/tweets', {'q':'bitcoin'})
for item in r:
print(item)
BLOCK_TIP_HEIGHT = os.path.expanduser('./BLOCK_TIP_HEIGHT')
DIFFICULTY = os.path.expanduser('./DIFFICULTY')
OLD_BLOCK_TIME = os.path.expanduser('./OLD_BLOCK_TIME')
ACCESS_TOKEN_SECRET = os.path.expanduser('./twitter_access_tokens/access_token_secret.txt')
ACCESS_TOKEN = os.path.expanduser('./twitter_access_tokens/access_token.txt')
CONSUMER_API_KEY = os.path.expanduser('./twitter_access_tokens/consumer_api_key.txt')
CONSUMER_API_SECRET_KEY = os.path.expanduser('./twitter_access_tokens/consumer_api_secret_key.txt')
cak = getData(CONSUMER_API_KEY)
cask = getData(CONSUMER_API_SECRET_KEY)
at = getData(ACCESS_TOKEN)
ats = getData(ACCESS_TOKEN_SECRET)
obt = getData(OLD_BLOCK_TIME)
api = TwitterAPI(cak,cask,at,ats)
getMempoolAPI('https://mempool.space/api/v1/difficulty-adjustment', DIFFICULTY)
getMempoolAPI('https://mempool.space/api/blocks/tip/height', BLOCK_TIP_HEIGHT)
# searchBitcoin()
# print(blockTime())
# print(getMillis())
# print(getSeconds())
# tweetBlockTime(blockTime())
m = hashlib.sha256()
m.update(b"Nobody inspects")
m.update(b" the spammish repetition")
print(m.digest())
# b'\x03\x1e\xdd}Ae\x15\x93\xc5\xfe\\\x00o\xa5u+7\xfd\xdf\xf7\xbcN\x84:\xa6\xaf\x0c\x95\x0fK\x94\x06'
print(m.digest_size)
print("WEEBLE_WOBBLE="+WEEBLE_WOBBLE())
# 32
print(m.block_size)
# 64
print(m.hexdigest())
def HEX_MESSAGE_DIGEST(recipient, message):
n = hashlib.sha256()
n.update(bytes(recipient, 'utf-8'))
n.update(bytes(message, 'utf-8'))
n.update(bytes(btc_unix_time, 'utf-8'))
# print(n.digest())
# b'\x03\x1e\xdd}Ae\x15\x93\xc5\xfe\\\x00o\xa5u+7\xfd\xdf\xf7\xbcN\x84:\xa6\xaf\x0c\x95\x0fK\x94\x06'
# print(n.digest_size)
# 32
# print(n.block_size)
# 64
# print(n.hexdigest())
return n.hexdigest()
def syndicateMessage(block_time):
if (block_time != obt):
# r = api.request('statuses/update',
# {'status':
# block_time+":"+getSeconds
# })
if is_tool('nostril'):
message = "test twitter/nostr syndication"
digest = HEX_MESSAGE_DIGEST(GPGID, message)
r = api.request('statuses/update',
{'status':
"GPGID:" + GPGID
+ ':MESSAGE:' + message
+ ':DIGEST:' + digest
+ ':TOOL:' + str(is_tool('nostril'))
+ ':WHICHTOOL:' + str(which_tool('nostril'))
+ ':BTC:UNIX:' + BTC_UNIX_TIME()
})
else:
message = "test twitter syndication"
digest = HEX_MESSAGE_DIGEST(GPGID, message)
r = api.request('statuses/update',
{'status':
"GPGID:"+GPGID
+ ':MESSAGE:' + message
+ ':DIGEST:' + digest
+ 'BTC:UNIX:' + BTC_UNIX_TIME()
})
# r = api.request('statuses/update', \
# {'status': HEX_MESSAGE_DIGEST(GPGID,"test message")})
# print(BTC_UNIX_TIME)
# exit()
if (r.status_code == 200):
print('api.request SUCCESS')
else:
print('api.request FAILURE')
else:
print('tweetBlockTime() FAILURE')
def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
# from whichcraft import which
from shutil import which
# from distutils.spawn import find_executable
# return find_executable(name) is not None
return which(name) is not None
def which_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
# from whichcraft import which
from shutil import which
# from distutils.spawn import find_executable
# return find_executable(name) is not None
return which(name)
global NOSTRIL
NOSTRIL = is_tool('nostril')
print(NOSTRIL)
print(BTC_UNIX_TIME())
global GPGID
GPGID = 'BB06757B'
# HEX_MESSAGE_DIGEST(GPGID, "test message")
HEX_MESSAGE_DIGEST(GPGID, str(NOSTRIL))
syndicateMessage(blockTime())