Skip to content

Commit 3ba4d1a

Browse files
Merge pull request #1 from laurentalacoque/passwordless
Passwordless authentication for emails and photo uploads
2 parents 23056ab + 5125752 commit 3ba4d1a

File tree

12 files changed

+679
-431
lines changed

12 files changed

+679
-431
lines changed

.gitignore

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# ignore specific files
2-
scripts/.credentials
32
scripts/*.jpg
43
scripts/*.log
4+
55
#ignore launcher
66
photobooth.sh
7+
scripts/configuration.json
8+
scripts/client_id.json
9+
scripts/credentials.dat
10+
711
# ignore log and animation frames
812
run.log
913
scripts/animframe*.*
@@ -13,12 +17,3 @@ scripts/*.pyc
1317

1418
# ignore emacs backupfiles
1519
scripts/*.py~
16-
17-
18-
# ignore credentials
19-
scripts/*.cred
20-
scripts/*.json
21-
scripts/*.dat
22-
23-
# ignore album.id file
24-
scripts/album.id

Photos/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This directory will be populated with archived versions
2+
of your photos.
3+
- You can disable this by setting "local_archive" key to
4+
'false' in your script/configuration.json file
5+
- You can change the destination directory by setting the
6+
"local_archive_dir" to "/path/to/the/destination/directory"

scripts/config.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

scripts/configuration.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import json
2+
import os
3+
4+
class Configuration():
5+
# default values
6+
user_name = None
7+
logo_file = None
8+
countdown1 = 5 # seconds of preview before first snap
9+
countdown2 = 3 # seconds of preview between snaps (Four pictures mode)
10+
photoCaption = "" # Caption in the photo album
11+
ARCHIVE = True # Do we archive photos locally
12+
archive_dir = os.path.join("..","Photos") # Where do we archive photos
13+
albumID = None # use install_credentials.py to create 'album.id'
14+
emailSubject = "Here's your photo!" # subject line of the email sent from the photobooth
15+
emailMsg = "Greetings, here's your photo sent from the photobooth" # Brief body of the message sent from the photobooth
16+
full_screen = True #Start application in full screen
17+
enable_email = True #Enable the 'send email" feature
18+
enable_upload = True #Enable the upload feature
19+
enable_hardware_buttons = False #Enable hardware buttons
20+
21+
#init
22+
def __init__(self,configuration_file_name):
23+
self.config_file = configuration_file_name
24+
self.is_valid = False
25+
self.__read_config_file()
26+
27+
def __read_config_file(self):
28+
self.is_valid = True
29+
try:
30+
with open(self.config_file, 'r') as content_file:
31+
file_content = content_file.read()
32+
config = json.loads(file_content)
33+
except Exception as error:
34+
print "Error while parsing %s config file : %s"%(self.config_file,error)
35+
self.is_valid = False
36+
return False
37+
if "gmail_user" in config.keys(): self.user_name = config['gmail_user']
38+
else:
39+
#mandatory configuration!!
40+
self.is_valid = False
41+
42+
43+
# all other configuration keys are optional
44+
if "countdown_before_snap" in config.keys(): self.countdown1 = config["countdown_before_snap"]
45+
if "countdown_inter_snap" in config.keys(): self.countdown2 = config["countdown_inter_snap"]
46+
if "snap_caption" in config.keys(): self.photoCaption = config["snap_caption"]
47+
if "local_archive" in config.keys(): self.ARCHIVE = config["local_archive"]
48+
if "local_archive_dir" in config.keys(): self.archive_dir = config["local_archive_dir"]
49+
if "google_photo_album_id" in config.keys(): self.albumID = config["google_photo_album_id"]
50+
if "email_subject" in config.keys(): self.emailSubject = config["email_subject"]
51+
if "email_body" in config.keys(): self.emailMsg = config["email_body"]
52+
if "logo_file" in config.keys(): self.logo_file = config["logo_file"]
53+
if "full_screen" in config.keys(): self.full_screen = config["full_screen"]
54+
if "enable_email" in config.keys(): self.enable_email = config["enable_email"]
55+
if "enable_upload" in config.keys(): self.enable_upload = config["enable_upload"]
56+
if "enable_hardware_buttons" in config.keys(): self.enable_hardware_buttons = config["enable_hardware_buttons"]
57+
58+
59+
return self.is_valid
60+
61+
62+
def write(self):
63+
myconfig = {
64+
"gmail_user": self.user_name,
65+
"countdown_before_snap": self.countdown1,
66+
"countdown_inter_snap": self.countdown2,
67+
"snap_caption": self.photoCaption,
68+
"local_archive" : self.ARCHIVE,
69+
"local_archive_dir" : self.archive_dir,
70+
"google_photo_album_id" : self.albumID,
71+
"email_subject": self.emailSubject,
72+
"email_body":self.emailMsg,
73+
"logo_file": self.logo_file,
74+
"full_screen": self.full_screen,
75+
"enable_email": self.enable_email,
76+
"enable_upload": self.enable_upload,
77+
"enable_hardware_buttons": self.enable_hardware_buttons
78+
}
79+
try:
80+
with open(self.config_file,'w') as config:
81+
config.write(json.dumps(myconfig, indent =4, sort_keys=True))
82+
except Exception as error:
83+
raise ValueError("Problem writing %s configuration file: %s"%(self.config_file,error))
84+
85+
86+
if __name__ == "__main__":
87+
88+
config = Configuration("myconf.conf")
89+
if not config.is_valid:
90+
config.write()

scripts/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@
4242
EMAIL_BUTTON_IMG = "ressources/ic_email.png"
4343
OAUTH2_REFRESH_PERIOD = 1800000 # interval between two OAuth2 token refresh (ms)
4444
HARDWARE_POLL_PERIOD = 100 # poll interval for buttons (ms)
45+
46+
CONFIGURATION_FILE = "configuration.json"
47+
APP_ID_FILE = "client_id.json"
48+
CREDENTIALS_STORE_FILE = "credentials.dat"

scripts/credentials.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

scripts/fakehardware.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,9 @@ def capture_continuous(self, output):
5454

5555
def close(self):
5656
del self.cam
57-
58-
class Buttons():
59-
def __init__(self, buttons_pins=[12, 8, 14], mode=1, active_state=1):
60-
self.buttons_pins = buttons_pins
61-
self.mode = mode
62-
self.active_state = active_state
63-
self.hw_state = 0
64-
self.counter = 0
65-
66-
def __del__(self):
67-
pass
6857

69-
def state(self):
70-
self.counter += 1
71-
if self.counter >= 50:
72-
self.counter = 0
73-
self.hw_state = (self.hw_state + 1) % 3
74-
return self.hw_state + 1
75-
else:
76-
return 0
7758

7859

7960
if __name__ == '__main__':
8061
camera = Camera()
81-
camera.capture("out.jpg")
62+
camera.capture("out.jpg")

0 commit comments

Comments
 (0)