Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
lleans committed Apr 2, 2021
1 parent e700b5d commit a2b340c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
24 changes: 9 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import scriptabsen
import values
import scriptabsen as script
import pytz
from time import time, sleep
import time
from datetime import datetime

print("Ready")

while True:
sleep(5 - time() % 5)

time.sleep(5)
WIB = pytz.timezone('Asia/Jakarta')
time_now = datetime.now(WIB)

if (time_now.strftime('%H') == '05' and
time_now.strftime('%M') == '58' and
time_now.strftime('%a') != 'Sat' and
time_now.strftime('%a') != 'Sun'):
temp = scriptabsen.runscript(values.email(), values.password(), values.browser())
if time_now.strftime('%H') == '05' and time_now.strftime('%M') == '58' and time_now.strftime('%a') != 'Sat' and time_now.strftime('%a') != 'Sun':
temp = script.runscript(values.email, values.password, values.browser())
times = datetime.now(WIB)
if(temp == True):
print("Absen berhasil pada " + times.strftime('%c'))
print("Absen berhasil pada", times.strftime('%c'))
elif(temp == False):
print("Absen gagal, SERVER SEKOLAH KENTANK, mencoba lagi " +
print("Absen gagal, SERVER SEKOLAH KENTANK, mencoba lagi",
times.strftime('%c'))
ass = scriptabsen.override(values.email(), values.password(), values.browser())
if ass == True:
timee = datetime.now(WIB)
print("Absen berhasil pada " + timee.strftime('%c'))
if script.override(values.email, values.password, values.browser()) == True:
print("Absen berhasil pada " + datetime.now(WIB).strftime('%c'))
else:
print("Server-mu Down " + times.strftime('%c'))
13 changes: 4 additions & 9 deletions scriptabsen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from selenium import webdriver
import pytz
import time
from time import sleep
from datetime import datetime


Expand All @@ -27,13 +25,10 @@ def runscript(email, password, browser):
browser.get("https://siswa.smktelkom-mlg.sch.id/presnow")

while True:
WIB = pytz.timezone('Asia/Jakarta')
time_now = datetime.now(WIB)
if time_now.strftime('%H') == '06' and time_now.strftime('%M') == '00':
browser.refresh()
time_now = datetime.now(pytz.timezone('Asia/Jakarta'))
if time_now.strftime('%H') == '06':
if cek_absen(browser) == False:
absen(browser)
browser.refresh()
if cek_absen(browser) == True:
logout(browser)
return True
Expand All @@ -54,6 +49,7 @@ def absen(browser):


def cek_absen(browser):
browser.refresh()
tmp = browser.find_element_by_class_name('number')
if(tmp.text == 'Masuk'):
return True
Expand All @@ -68,6 +64,5 @@ def logout(browser):

def override(email, password, browser):
while True:
data = runscript(email, password, browser)
if data == True:
if runscript(email, password, browser) == True:
return True
12 changes: 2 additions & 10 deletions values.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@
#
#
# Emailmu Si AKAD blyat
Email = ""
email = ""
#
#
#
# Passwordmu Si AKAD blyat
Password = ""


def email():
return Email


def password():
return Password
password = ""

def browser():
chromes = webdriver.ChromeOptions()
Expand Down

0 comments on commit a2b340c

Please sign in to comment.