-
Notifications
You must be signed in to change notification settings - Fork 8
/
get-tito-registrations.php
133 lines (103 loc) · 4.1 KB
/
get-tito-registrations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
$event = $argv[1];
$config_file = dirname(__FILE__).'/.tito-'.$event.'.json';
if(!file_exists($config_file)) {
echo "Tito config file was not found\n";
die();
}
$config = json_decode(trim(file_get_contents($config_file)));
function get_tito($url) {
global $config;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Token token=' . $config->token
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
return json_decode($response, true);
}
function normalize_url($url) {
if($url == '') return $url;
if(!preg_match('/^https?:\/\//', $url))
return 'http://'.$url;
return $url;
}
$registrations = get_tito($config->registrations);
if(!file_exists(dirname(__FILE__).'/data/'.$event)) {
mkdir(dirname(__FILE__).'/data/'.$event, 0755);
}
file_put_contents(dirname(__FILE__).'/data/'.$event.'/tito.json', json_encode($registrations, JSON_PRETTY_PRINT+JSON_UNESCAPED_SLASHES));
$ticketData = [];
foreach($registrations['data'] as $reg) {
$timestamp = $reg['attributes']['completed-at'];
$email = $reg['attributes']['email'];
echo "======\n";
$hash = md5(strtolower(trim($email)));
echo $email . "\n";
echo $hash . "\n";
$dir = __DIR__.'/data/'.$event.'/'.$hash;
@mkdir($dir, 0755);
$website = false;
$show = false;
$attendance = [];
$ticket_type = [];
if(isset($reg['relationships']['tickets']['links']['related'])) {
$ticket = get_tito($reg['relationships']['tickets']['links']['related']);
if($ticket && isset($ticket['data'][0])) {
$ticket = $ticket['data'][0];
$name = $ticket['attributes']['name'];
if(isset($ticket['attributes']['answers']) && is_array($ticket['attributes']['answers'])) {
foreach($ticket['attributes']['answers'] as $question=>$answer) {
if($question == 'your-personal-website')
$website = normalize_url($answer);
if($question == 'would-you-like-to-be-shown-on-the-public')
$show = ($answer == 'Yes, show me on the guest list' ? 'yes' : 'no');
if($question == 'would-you-like-to-be-seen-on-the-public') // for nyc
$show = ($answer == 'Yes, show me on the guest list' ? 'yes' : 'no');
if($question == 'event-attendance')
$attendance = $answer;
}
}
echo $name . "\n";
echo $timestamp . "\n";
echo $website . "\n";
echo $show . "\n";
file_put_contents($dir.'/ticket.json', json_encode($ticket, JSON_PRETTY_PRINT+JSON_UNESCAPED_SLASHES));
$fn = $dir.'/photo.jpg';
if(!file_exists($fn)) {
// Try to download the profile photo from Gravatar
$ch = curl_init('https://www.gravatar.com/avatar/'.$hash.'.jpg?d=404');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$imgdata = curl_exec($ch);
if($imgdata) {
echo "found gravatar\n";
@mkdir($dir, 0755);
file_put_contents($fn, $imgdata);
} else {
echo "no gravatar\n";
}
}
// Fetch "Releases" to find out what type of ticket they registered for
if(isset($ticket['relationships']['release']['links']['related'])) {
$release = get_tito($ticket['relationships']['release']['links']['related']);
file_put_contents($dir.'/release.json', json_encode($release, JSON_PRETTY_PRINT+JSON_UNESCAPED_SLASHES));
if(isset($release['data']['attributes']['title'])) {
$ticket_type[] = $release['data']['attributes']['title'];
}
}
}
$thisTicket = [
'name' => $name,
'website' => $website,
'email' => $email,
'timestamp' => $timestamp,
'show' => $show,
'attendance' => $attendance,
'ticket_type' => $ticket_type,
];
$ticketData[] = $thisTicket;
file_put_contents($dir.'/summary.json', json_encode($thisTicket, JSON_PRETTY_PRINT+JSON_UNESCAPED_SLASHES));
}
}
file_put_contents(dirname(__FILE__).'/data/'.$event.'/tickets.json', json_encode($ticketData, JSON_PRETTY_PRINT));