1 |
#!/usr/bin/perl |
2 |
|
3 |
use Pg; |
4 |
|
5 |
$start = 0; |
6 |
$db = "stock"; |
7 |
$db_user = "postgres"; |
8 |
$db_password = "ybgz004"; |
9 |
|
10 |
$conn = Pg::connectdb("dbname=$db user=$db_user password=$db_password"); |
11 |
|
12 |
while(<>) { |
13 |
if ($start) { |
14 |
chop; |
15 |
($code, $date, $open, $high, $low, $close, $volume) = split(","); |
16 |
$date =~ /(..)(..)(..)/; |
17 |
$date = "20${1}-${2}-${3}"; |
18 |
#print "$code,$date,$open,$high,$low,$close,$volume\n"; |
19 |
#print; |
20 |
$query = "INSERT INTO market VALUES ('$code', '$date', $open, $high, $low, $close, $volume)"; |
21 |
#print "$query\n"; |
22 |
$result = $conn->exec($query); |
23 |
} |
24 |
if (/^-- CUT/) { |
25 |
# sit up and take notice |
26 |
$start = 1; |
27 |
} |
28 |
} |