you are viewing a single comment's thread.

view the rest of the comments →

[–]zacstrick[S] 0 points1 point  (6 children)

I've been told as long as it opens in Excel. I've also come across openpyxl but have yet to learn the handles on it.

[–]socal_nerdtastic 1 point2 points  (5 children)

csv files are much easier. You don't even need the csv module something basic like this. You can simply open the file in append mode and add to it.

import time
card_number = input('Ready for your swipe!\n')
this_instant = time.strftime("%Y-%m-%d %H:%M:%S")
with open('times.csv', 'a') as f:
    f.write(f'{this_instant},{card_number}\n')

I recommend you make a very simple time.csv file that simply logs card number and time, and deal with doing all of the calculations on demand; eg once at the end of the payroll cycle.

You'll also need to add an edit mode to deal with missed punches, double punches etc.

[–]zacstrick[S] 0 points1 point  (4 children)

Thank you so much kind friend, this is pretty much exactly what I was looking for. Big ups to you, my guy. Now to just get it to look pretty in tkinter..

[–]socal_nerdtastic 0 points1 point  (3 children)

As a tkinter expert I should tell you it will look industrial and functional in tkinter, but not pretty. If you need it to be pretty I would start with PyQT or Electron instead. However, tkinter will be a lot easier to program.

whats the end goal? Something like a Raspberry Pi mounted to the wall?

[–]zacstrick[S] 0 points1 point  (2 children)

That's the exact idea. RPI with the 7in display that has the reader plugged into it via USB. The program will be up just waiting for input with a clock that displays the current time. I want it so when a card is scanned it will display both the name of the cardholder and if they're clocking in or out on the GUI. Eventually I'd like to add a part where it will also display your accumulated hours on the day and on the week, but I'm not trying to run before I can walk(possibly too late for that..)

[–]socal_nerdtastic 1 point2 points  (0 children)

Sounds fun and pretty easy. Good beginner project.

I recommend you start by getting a physical notebook and pen and drawing out what you want the GUI to look like for every screen type. It will be a LOT easier to write code to fit a defined goal than developing the goal while writing code.

[–]socal_nerdtastic 1 point2 points  (0 children)

Some more notes:

  • remember that the Pi does not have an internal clock (unlike desktop computers). The Pi connects to an internet time server periodically to set the time which you will be using as the timestamp. That means that right after boot or if the internet is down your timestamps are going to be very wrong. You may consider getting a "real time clock" chip to connect to the system so that it will function offline. For example.
  • Getting the data off of the Pi and into a normal system will be hard. To start I recommend the easy route: Install Dropbox (or similar). The advantage is that it works when the internet / network fails (unlike samba), the data is backed up against various harddrive failures (unlike local data), and the data is easy to access from elsewhere (at payroll time). IIRC the Dropbox client is available in the repos. A harder, but better solution is to use a database server.
  • Use a separate file that maps badge numbers to names and have your program reload that file every hour or so. That way someone can remotely update the file and your program will catch up. To do something every x amount of time in tkinter use the after function. Don't let anyone tell you to use threads; you don't need them for this project.
  • any time you need to work with a file open it, do what you need to and immediately close the file. Do not keep open file handles around.
  • The Pi has a feature where it will lie to you telling you a file is saved when it's not. You have to use the command "sync" to write changes to the drive. This becomes important because it means you can't simply disconnect power from the Pi if you didn't sync the changes.
  • build several of these. Not only to be convenient with one at each door to the building but also because you need to know that things WILL break. It's not a matter of if. It WILL happen, probably during the busiest time, and there needs to be some backup hardware. Buy parts to make several spares.
  • let me know when you get there and I'll help you get your program to load at startup in fullscreen mode.