|
|
|
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
|
|
import datetime
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
date = now.strftime('%Y%m%d')
|
|
|
|
|
|
|
|
server_name = 'freya.cayangqu.com'
|
|
|
|
|
|
|
|
try:
|
|
|
|
nama_log = f"auto_replytoaccNretweet.log.{sys.argv[2]}"
|
|
|
|
except:
|
|
|
|
nama_log = "auto_replytoaccNretweet.log"
|
|
|
|
|
|
|
|
def twit_sent():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit sent: {output}"
|
|
|
|
|
|
|
|
def twit_sent_2():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit sent: {output}"
|
|
|
|
|
|
|
|
def twit_sent_3():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit sent: {output}"
|
|
|
|
|
|
|
|
def twit_failed():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit failed: {output}"
|
|
|
|
|
|
|
|
def twit_failed_2():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit failed: {output}"
|
|
|
|
|
|
|
|
def twit_failed_3():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit failed: {output}"
|
|
|
|
|
|
|
|
def quote_tweet():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit quoted: {output}"
|
|
|
|
|
|
|
|
def quote_tweet2():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit quoted: {output}"
|
|
|
|
|
|
|
|
def quote_tweet3():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit quoted: {output}"
|
|
|
|
|
|
|
|
def reply_tweet():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit replied: {output}"
|
|
|
|
|
|
|
|
def reply_tweet2():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit replied: {output}"
|
|
|
|
|
|
|
|
def reply_tweet3():
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = wc_process.communicate()
|
|
|
|
return f"Twit replied: {output}"
|
|
|
|
|
|
|
|
def twit_failed2():
|
|
|
|
with open(f"/home/telakses/twitmonitor/twit_failed.txt", 'w') as f:
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = grep_process.communicate()
|
|
|
|
#print(output)
|
|
|
|
f.write(output)
|
|
|
|
f = open("/home/telakses/twitmonitor/twit_failed.txt", "r")
|
|
|
|
result = {
|
|
|
|
"error_401":0,
|
|
|
|
"error_403":0,
|
|
|
|
"error_400":0,
|
|
|
|
"error_429":0,
|
|
|
|
"error_503":0,
|
|
|
|
}
|
|
|
|
for x in f:
|
|
|
|
error=x.split()
|
|
|
|
raw_error=error[14]
|
|
|
|
clean_error = raw_error[1:4]
|
|
|
|
if(int(clean_error) == 401):
|
|
|
|
result["error_401"]+=1
|
|
|
|
elif(int(clean_error) == 403):
|
|
|
|
result["error_403"]+=1
|
|
|
|
elif(int(clean_error) == 400):
|
|
|
|
result["error_400"]+=1
|
|
|
|
elif(int(clean_error) == 429):
|
|
|
|
result["error_429"]+=1
|
|
|
|
else:
|
|
|
|
result["error_503"]+=1
|
|
|
|
return result
|
|
|
|
|
|
|
|
def twit_failed2_2():
|
|
|
|
with open(f"/home/telakses/twitmonitor/twit_failed_log2.txt", 'w') as f:
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = grep_process.communicate()
|
|
|
|
#print(output)
|
|
|
|
f.write(output)
|
|
|
|
f = open("/home/telakses/twitmonitor/twit_failed_log2.txt", "r")
|
|
|
|
result = {
|
|
|
|
"error_401":0,
|
|
|
|
"error_403":0,
|
|
|
|
"error_400":0,
|
|
|
|
"error_429":0,
|
|
|
|
"error_503":0,
|
|
|
|
}
|
|
|
|
for x in f:
|
|
|
|
error=x.split()
|
|
|
|
raw_error=error[14]
|
|
|
|
clean_error = raw_error[1:4]
|
|
|
|
if(int(clean_error) == 401):
|
|
|
|
result["error_401"]+=1
|
|
|
|
elif(int(clean_error) == 403):
|
|
|
|
result["error_403"]+=1
|
|
|
|
elif(int(clean_error) == 400):
|
|
|
|
result["error_400"]+=1
|
|
|
|
elif(int(clean_error) == 429):
|
|
|
|
result["error_429"]+=1
|
|
|
|
else:
|
|
|
|
result["error_503"]+=1
|
|
|
|
return result
|
|
|
|
|
|
|
|
def twit_failed2_3():
|
|
|
|
with open(f"/home/telakses/twitmonitor/twit_failed_log3.txt", 'w') as f:
|
|
|
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True)
|
|
|
|
grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True)
|
|
|
|
output, error = grep_process.communicate()
|
|
|
|
#print(output)
|
|
|
|
f.write(output)
|
|
|
|
f = open("/home/telakses/twitmonitor/twit_failed_log3.txt", "r")
|
|
|
|
result = {
|
|
|
|
"error_401":0,
|
|
|
|
"error_403":0,
|
|
|
|
"error_400":0,
|
|
|
|
"error_429":0,
|
|
|
|
"error_503":0,
|
|
|
|
}
|
|
|
|
for x in f:
|
|
|
|
error=x.split()
|
|
|
|
raw_error=error[14]
|
|
|
|
clean_error = raw_error[1:4]
|
|
|
|
if(int(clean_error) == 401):
|
|
|
|
result["error_401"]+=1
|
|
|
|
elif(int(clean_error) == 403):
|
|
|
|
result["error_403"]+=1
|
|
|
|
elif(int(clean_error) == 400):
|
|
|
|
result["error_400"]+=1
|
|
|
|
elif(int(clean_error) == 429):
|
|
|
|
result["error_429"]+=1
|
|
|
|
else:
|
|
|
|
result["error_503"]+=1
|
|
|
|
return result
|
|
|
|
|
|
|
|
with open(f"/home/telakses/twitmonitor/twit_monitor1.txt", 'w') as f:
|
|
|
|
f.write(quote_tweet())
|
|
|
|
f.write(reply_tweet())
|
|
|
|
error = twit_failed2()
|
|
|
|
f.write(f"Error 401: {error['error_401']}\n")
|
|
|
|
f.write(f"Error 403: {error['error_403']}\n")
|
|
|
|
f.write(f"Error 400: {error['error_400']}\n")
|
|
|
|
f.write(f"Error 429: {error['error_429']}\n")
|
|
|
|
f.write(f"Error 503: {error['error_503']}\n")
|
|
|
|
|
|
|
|
with open(f"/home/telakses/twitmonitor/twit_monitor2.txt", 'w') as f:
|
|
|
|
f.write(quote_tweet2())
|
|
|
|
f.write(reply_tweet2())
|
|
|
|
error2 = twit_failed2_2()
|
|
|
|
f.write(f"Error 401: {error2['error_401']}\n")
|
|
|
|
f.write(f"Error 403: {error2['error_403']}\n")
|
|
|
|
f.write(f"Error 400: {error2['error_400']}\n")
|
|
|
|
f.write(f"Error 429: {error2['error_429']}\n")
|
|
|
|
f.write(f"Error 503: {error2['error_503']}\n")
|
|
|
|
|
|
|
|
with open(f"/home/telakses/twitmonitor/twit_monitor3.txt", 'w') as f:
|
|
|
|
f.write(quote_tweet3())
|
|
|
|
f.write(reply_tweet3())
|
|
|
|
error3 = twit_failed2_3()
|
|
|
|
f.write(f"Error 401: {error3['error_401']}\n")
|
|
|
|
f.write(f"Error 403: {error3['error_403']}\n")
|
|
|
|
f.write(f"Error 400: {error3['error_400']}\n")
|
|
|
|
f.write(f"Error 429: {error3['error_429']}\n")
|
|
|
|
f.write(f"Error 503: {error3['error_503']}\n")
|