Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Adding btach file/Windows support #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ Run the following command in your terminal and then, enter your amFOSS CMS Crede
wget https://raw.githubusercontent.com/amfoss/attendance-tracker/master/install.sh -O install.sh ; bash -e install.sh
```

## For Mac

You have add your absolute path in 3 places after running the above command
```
* config
* install.sh
* attendance.py
```

To get Absolute path just
```pwd```

## Update Your Credentials
This should be done whenever you change your password.

Expand Down
14 changes: 10 additions & 4 deletions attendance/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from urllib.request import urlopen
from subprocess import Popen, PIPE
from os.path import expanduser
from os import getcwd
from sys import platform as _platform


if _platform == "linux" or _platform == "linux2":
if "linux" in _platform:
file_path = "/opt/attendance/"
elif _platform == "darwin":
file_path = f"{expanduser('~')}/.attendance/"
file_path = f"/Users/{sys.argv[1]}/.attendance/"
elif "win" in _platform:
file_path = getcwd()+'\\'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay,
We should have a folder for storing the script right,
I would propose to have it in a folder itself like .attendance for having uniformity



def get_credentials():
Expand All @@ -39,7 +41,11 @@ def check_internet_connection():

def get_wifi_list():
ssid_list = []
p = Popen([file_path + 'get_ssid_names.sh'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if "win" in _platform:
p = Popen([file_path + 'get_ssid_names.bat'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
else:
p = Popen([file_path + 'get_ssid_names.sh'], stdin=PIPE, stdout=PIPE, stderr=PIPE)

output, err = p.communicate()
output = str(output).split("\\n")
if _platform == "darwin":
Expand Down
2 changes: 1 addition & 1 deletion attendance/config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ case "${unameOut}" in
esac

if [[ "$machine" = "Mac" ]];then
python3 "$HOME"/.attendance/attendance.py >/tmp/stdout.log 2>/tmp/stderr.log
/usr/local/bin/python3 /Users/"$1"/.attendance/attendance.py "$1" >/tmp/stdout.log 2>/tmp/stderr.log
else
python3 /opt/attendance/attendance.py &> /opt/attendance/attendance.log

Expand Down
3 changes: 3 additions & 0 deletions attendance/get_ssid_names.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

set interface=`ip link | findstr -Po '^\d+:\s+\K[^:]+' | findstr 'w'`
netsh %interface% show all | findstr ESSID
2 changes: 1 addition & 1 deletion attendance/get_ssid_names.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ if [[ "$machine" = "Mac" ]];then
else
interface=`ip link | grep -Po '^\d+:\s+\K[^:]+' | grep 'w'`
sudo iwlist ${interface} scan | grep ESSID
fi
fi
11 changes: 7 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ esac

# install pip, git and requests
if [[ "$machine" = "Mac" ]]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
if [[ $(command -v brew) == "" ]]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install python3
pip3 install requests
readonly attendance_folder_path="$HOME/.attendance"
readonly attendance_folder_path="/Users/$(logname)/.attendance"
else
sudo apt install python3-pip git -y
sudo -H pip3 install requests
Expand All @@ -35,7 +37,8 @@ sudo cp -r attendance-tracker/attendance/. "$attendance_folder_path"/.
sudo chmod +x "$attendance_folder_path"/config "$attendance_folder_path"/get_ssid_names.sh

# Add a new cron-job
croncmd="*/1 * * * * ${attendance_folder_path}/config"
username=$(logname)
croncmd="*/1 * * * * ${attendance_folder_path}/config $username"
# write out current crontab
sudo crontab -l > mycron || touch mycron
# echo new cron into cron file if it does not exist,
Expand All @@ -54,4 +57,4 @@ rm install.sh
# fetch creds from user and store them
cd "$attendance_folder_path"
sudo python3 get_and_save_credentials.py
cd ~
cd ~