get emails func
This commit is contained in:
parent
03dae17348
commit
3273b60476
1
registrations/jonathan.txt
Normal file
1
registrations/jonathan.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"name":"Jonathan","email":"jonathanouwerx@me.com","org_website":"","plus_one":"","receive_communication":"on"}
|
41
ticket.v
41
ticket.v
@ -17,8 +17,9 @@ pub fn new_app() &App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
mut app := new_app()
|
// mut app := new_app()
|
||||||
vweb.run(app, 8000)
|
// vweb.run(app, 8000)
|
||||||
|
get_emails_from_dir('registrations')?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -27,12 +28,12 @@ pub fn (mut app App) index() vweb.Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Registration {
|
pub struct Registration {
|
||||||
name string
|
name string
|
||||||
email string
|
email string
|
||||||
org_website string
|
org_website string
|
||||||
plus_one string
|
plus_one string
|
||||||
receive_communication string
|
receive_communication string
|
||||||
timestamp time.Time
|
timestamp i64
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) exists() vweb.Result {
|
pub fn (mut app App) exists() vweb.Result {
|
||||||
@ -70,7 +71,7 @@ pub fn (mut app App) register(name string, email string, org_website string, plu
|
|||||||
org_website: org_website,
|
org_website: org_website,
|
||||||
plus_one: plus_one,
|
plus_one: plus_one,
|
||||||
receive_communication: receive_communication,
|
receive_communication: receive_communication,
|
||||||
timestamp: time.now()
|
timestamp: time.now().unix_time()
|
||||||
}
|
}
|
||||||
path := 'registrations/${email}.txt'
|
path := 'registrations/${email}.txt'
|
||||||
if os.exists(path) { return app.exists()}
|
if os.exists(path) { return app.exists()}
|
||||||
@ -96,4 +97,26 @@ pub fn (mut app App) registrations() vweb.Result {
|
|||||||
resp += content
|
resp += content
|
||||||
}
|
}
|
||||||
return app.html(resp)
|
return app.html(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_emails_from_dir (path string) ?string {
|
||||||
|
|
||||||
|
mut emails := []string
|
||||||
|
|
||||||
|
mut files := os.ls(path)?// returns an array of strings
|
||||||
|
|
||||||
|
for file in files {
|
||||||
|
mut content := os.read_file('registrations/$file') or {'error'}
|
||||||
|
registration := json.decode(Registration, content)?
|
||||||
|
emails << registration.email
|
||||||
|
}
|
||||||
|
|
||||||
|
emails_string := emails.join(', ')
|
||||||
|
|
||||||
|
println(emails_string)
|
||||||
|
|
||||||
|
return emails_string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user