-
Notifications
You must be signed in to change notification settings - Fork 0
/
prs.php
203 lines (167 loc) · 5.45 KB
/
prs.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
require_once 'Zend/Loader.php';
require_once 'db.class.php';
require_once 'credentials.php';
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
/*
$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));
Else use cURL:
$sql = "select * from filme";
$stmt = $db->prepare($sql);
$stmt->execute();
while($temp = $stmt->fetch(PDO::FETCH_ASSOC))
{
$ch = curl_init($temp['poster']);
$fp = fopen('poster/'.$temp['id'].'.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo 'insert: '.$temp['id']."<br/>";
flush();
ob_flush();
}
exit;
*/
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
function getClientLoginHttpClient($user, $pass)
{
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
return $client;
}
$client = getClientLoginHttpClient(USERNAME, PASSWORD);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
// Get your spreadsheets feed
$feed = $spreadsheetService->getSpreadsheetFeed();
foreach($feed->entries as $entry) {
$title = $entry->title->text;
if ($title == "Filme") $id = $entry->id;
}
// Get spreadsheet key
$spreadsheetsKey = basename($id);
echo 'Your spreadsheet key is: ' . $spreadsheetsKey .'</br>';
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($spreadsheetsKey);
$feed = $spreadsheetService->getWorksheetFeed($query);
foreach($feed->entries as $entry) {
echo 'Your "'. $entry->title->text .'" worksheet ID is: ';
$worksheetId = basename($entry->id);
echo $worksheetId.'</br>';
}
$worksheetId = 'od6';
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($spreadsheetsKey);
$query->setWorksheetId($worksheetId);
$query->setMinRow(7);
$query->setMaxRow(10);
$colNr = 4;
$query->setMinCol($colNr);
$query->setMaxCol($colNr);
$query->setMinRow($startingRow);
$query->setMaxRow($endingRow);
$columnFeed = $spreadsheetService->getCellFeed($query);
foreach($columnFeed as $cellEntry){
$result[$cellEntry->cell->getRow()] = $cellEntry->cell->getText();
}
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($spreadsheetsKey);
$query->setWorksheetId($worksheetId);
$query->setMinRow(7);
$query->setMaxRow(10);
$colNr = 2;
$query->setMinCol($colNr);
$query->setMaxCol($colNr);
$query->setMinRow($startingRow);
$query->setMaxRow($endingRow);
$columnFeed = $spreadsheetService->getCellFeed($query);
foreach($columnFeed as $cellEntry){
$result2[$cellEntry->cell->getRow()] = $cellEntry->cell->getText();
}
$sql = "SELECT * from filme";
$stmt = $db->prepare($sql);
$stmt->execute();
$bestehende=array();
while($temp = $stmt->fetch(PDO::FETCH_ASSOC))
{
$bestehende[] = $temp['tt'];
$lastId = $temp['id'];
}
foreach ($result as $key => $res)
{
if( !in_array($res, $bestehende) && $key >= 6)
{
if($res != '.')
{
echo 'insert: '.$res."<br/>";
flush();
ob_flush();
$film = parse($res);
$sql = 'insert into filme (id, tt,name,plot,poster,rating, jahr) values (:id, :tt,:name,:plot,:poster,:rating, :jahr)';
$stmt=$db->prepare($sql);
$stmt->bindParam(':id', $result2[$key], PDO::PARAM_INT);
$stmt->bindParam(':tt', $res, PDO::PARAM_STR);
$stmt->bindParam(':name', $film['name'], PDO::PARAM_STR);
$stmt->bindParam(':plot', $film['plot'], PDO::PARAM_STR);
$stmt->bindParam(':poster', $film['poster'], PDO::PARAM_STR);
$stmt->bindParam(':rating', $film['rating'], PDO::PARAM_STR);
$stmt->bindParam(':jahr', $film['jahr'], PDO::PARAM_INT);
$stmt->execute();
}
$cnt++;
}
}
function parse($id)
{
$contents = file_get_contents('http://m.imdb.com/title/'.$id.'/');
// poster
$match = '';
preg_match('/src="http:\/\/ia\.media.*_S/', $contents, $match);
$poster = explode('src="',$match[0]);
$poster = $poster[1].'X675.jpg';
// plot
$match = '';
preg_match('/op="description.*?</is', $contents, $match);
$plot = explode('>', $match[0]);
$plot = explode('<', $plot[1]);
// rating
$match = '';
preg_match('/inline-block text-left vertically-middle">[0-9]\.?[0-9]?[0-9]?/', $contents, $match);
$rating = explode('>', $match[0]);
// name
$match = '';
preg_match('/:title\' content=".*"/s', $contents, $match);
$name = explode('content="', $match[0]);
$name = explode('(', $name[1]);
$jahr = explode(')', $name[1]);
return array('name' => trim(strip_tags($name[0])), 'poster' => $poster, 'plot' => trim($plot[0]), 'rating' => $rating[1], 'jahr' => $jahr[0]);
}
exit;
// Get cell feed
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($spreadsheetsKey);
$query->setWorksheetId($worksheetId);
$cellFeed = $spreadsheetService->getCellFeed($query);
// Echo all cells
foreach($cellFeed as $cellEntry) {
$row = $cellEntry->cell->getRow();
$col = $cellEntry->cell->getColumn();
$val = $cellEntry->cell->getText();
echo "$row, $col = $val</br>";
}
exit;
$updatedCell = $spreadsheetService->updateCell(3,
2,
'Hello from PHP!',
$spreadsheetsKey,
$worksheetId);
/*
*/
?>