You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.6 KiB
84 lines
3.6 KiB
2 years ago
|
#!/usr/bin/env python3
|
||
|
import subprocess
|
||
|
import datetime
|
||
|
import json
|
||
|
import sys
|
||
|
|
||
|
now = datetime.datetime.now()
|
||
|
date = now.strftime('%Y%m%d')
|
||
|
|
||
|
server_name = 'lala.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/ditolak/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_failed():
|
||
|
ls_process = subprocess.Popen(["cat",f"/home/ditolak/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 quote_tweet():
|
||
|
ls_process = subprocess.Popen(["cat",f"/home/ditolak/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 reply_tweet():
|
||
|
ls_process = subprocess.Popen(["cat",f"/home/ditolak/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 twit_failed2():
|
||
|
with open(f"/home/ditolak/twitmonitor/twit_failed.txt", 'w') as f:
|
||
|
ls_process = subprocess.Popen(["cat",f"/home/ditolak/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/ditolak/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
|
||
|
|
||
|
with open(f"/home/ditolak/twitmonitor/twit_monitor.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")
|