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.
103 lines
3.9 KiB
103 lines
3.9 KiB
#!/usr/bin/env python3 |
|
import subprocess |
|
import datetime |
|
import json |
|
import sys |
|
import os |
|
|
|
now = datetime.datetime.now() |
|
date = now.strftime('%Y%m%d') |
|
|
|
server_name = 'minji.cayangqu.com' |
|
|
|
try: |
|
nama_log = f"auto_rtlikesTweet.log.{sys.argv[2]}" |
|
except: |
|
nama_log = "auto_rtlikesTweet.log" |
|
|
|
|
|
def retweet(): |
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/modul-crm/tweetskrip/app/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) |
|
grep_process = subprocess.Popen(["grep", "retweet success"], 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 retweeted: {output}" |
|
|
|
def like_tweet(): |
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/modul-crm/tweetskrip/app/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) |
|
grep_process = subprocess.Popen(["grep", "like success"], 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 liked: {output}" |
|
|
|
def twit_failed(): |
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/modul-crm/tweetskrip/app/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) |
|
grep_process = subprocess.Popen(["grep", "Error"], 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 first_log(): |
|
with open(f"/home/telakses/modul-crm/tweetskrip/app/{sys.argv[1]}/log/{nama_log}", 'r') as f: |
|
lines = f.readlines() |
|
firstline = lines[0] |
|
firstsplit = firstline.split(" - ",1) |
|
output = firstsplit[0] |
|
|
|
return f"First log: {output}\n" |
|
|
|
def last_log(): |
|
with open(f"/home/telakses/modul-crm/tweetskrip/app/{sys.argv[1]}/log/{nama_log}", 'r') as f: |
|
lines = f.readlines() |
|
lastline = lines[-1] |
|
lastsplit = lastline.split(" - ",1) |
|
output = lastsplit[0] |
|
|
|
return f"Last log: {output}\n" |
|
|
|
def twit_failed2(): |
|
with open(f"/home/telakses/twitmonitor/twit_failed.txt", 'w') as f: |
|
ls_process = subprocess.Popen(["cat",f"/home/telakses/modul-crm/tweetskrip/app/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) |
|
grep_process = subprocess.Popen(["grep", "Error"], 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[12] |
|
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_monitor.txt", 'w') as f: |
|
#f.write(f"Dari log: {nama_log}\n") |
|
f.write(first_log()) |
|
f.write(last_log()) |
|
f.write(retweet()) |
|
f.write(like_tweet()) |
|
f.write(twit_failed()) |
|
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") |
|
f.write("\n") |