forked from ormestad/publications
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpub_script.php
71 lines (59 loc) · 1.77 KB
/
pub_script.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
<?php
require 'lib/global.php';
require 'lib/config.php';
ini_set('register_argc_argv', 0);
if (!isset($argc) || is_null($argc))
{
print('Not CLI mode');
die();
} else {
print("CLI mode\n");
}
$labid = $argv[1];
# Start forgery
$USER = new stdClass();
$USER->data = [];
$USER->data["uid"] = 1;
$USER->data["user_email"] = "[email protected]";
global $USER;
# End forgery
$pubmed=new PHPMed();
$researchers=new NGIresearchers();
$publications=new NGIpublications();
$labs=[];
if(isset($labid)) {
array_push($labs, [$labid, "cli_parameter"]);
} else {
while($lab=$labs_query->fetch_assoc()) {
$labs_query=sql_query("SELECT * FROM labs WHERE lab_status <> 'disabled' or lab_status IS NULL ORDER BY lab_name");
$id = $researchers->getClarityID($lab['lab_clarity_uri']);
array_push($labs, [$id, $lab['lab_name']]);
}
}
foreach($labs as $lab) {
$labid = $lab[0]; $labname = $lab[1];
print(date(c)." -- start ".$labname."\n");
if($lab=$researchers->getLab($labid)) {
$added=0;
$found=0;
// Build pubmed query with a limitation on publication date
date_default_timezone_set('UTC');
$timestamp = time() - ($CONFIG['publications']['max_days'] * 86400);
$dt = date('Y/m/d', $timestamp);
$pmq = '('.$lab['query']['query_string']['pi'].')' . ' AND ("'.$dt.'"[Date - Publication] : "3000"[Date - Publication])';
$data=$pubmed->parsedSearch($pmq);
$found=count($data);
foreach($data as $pmid => $article) {
$add=$publications->addPublication($article,$lab);
if($add['data']['status']=="added") {
$added++;
print("+ ".$article["uid"]."\n");
}
}
print(date(c)." -- found: ".$found.", added: ".$added."\n");
} else {
// Lab not found
print('Invalid Lab ID:' . $labid."\n");
}
}
?>