forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeloxom-v20040930
133 lines (119 loc) · 3.32 KB
/
deloxom-v20040930
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
#!/usr/bin/perl
##
## A blosxom-centric del.icio.us parser that
## creates blosxom entries of your daily
## del.icio.us links.
##
## Best if cron-ed to run daily.
##
## Make sure you check out the link output area near
## the bottom of the script for formatting options
## and info. on how to access other tags.
##
## By: Brett O'Connor (oconnorb AT dogheadbone.com)
## Mike Hostetler (thehaas AT binary.net)
##
## Last Revision Date: 2004-09-30
#############################################################
require XML::Parser;
require LWP::UserAgent;
require HTTP::Request::Common;
#your del.icio.us account info
$login = "your_login";
$password = "your_password";
#file name and location setup for ouputting to file
$timestamp = time();
$outfile = "/path/to/blosxom/entries/".$timestamp.".txt";
#ouput header and footer
$header = "today's del.icio.us links\n<ul>";
$footer = "</ul>(Keep your own bookmarks online at <a href=\"http://del.icio.us/\">del.icio.us.</a>)";
#api information (just in case it is changed)
#$api_url = "http://api.del.icio.us/1.0/api/etc"
$api_url = "http://del.icio.us/api";
$api_net_loc = "del.icio.us:80";
$api_realm = "del.icio.us API";
#get todays entries
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDat, $DayOfYear, $IsDST) =
localtime(time);
my $RealMonth = $Month + 1;
if ($RealMonth < 10)
{
$RealMonth = "0" . $RealMonth;
}
if ($Day < 10)
{
$Day = "0" . $Day;
}
$FixedYear = $Year + 1900;
$date = "$FixedYear-$RealMonth-$Day";
#create the output
my $parser = new XML::Parser (Style=>'Subs', Pkg=>'SubHandlers', ErrorContext=>
2);
$parser->setHandlers(Char => \&charData);
my $out;
$parser->parse(fetchPage($login,$password,$date));
#write out entry if to file
#$outputTo = 'screen'; #debugging purposes
$outputTo = 'file';
if ($out ne '') {
if ($outputTo eq 'file') {
open(FILE, ">$outfile");
print FILE "$header";
print FILE "$out";
print FILE "$footer";
close(FILE);
} else {
printf($header);
printf($out);
printf($footer);
}
}
#subroutines
sub fetchPage {
my ($user,$pass,$date) = @_;
my $browser = LWP::UserAgent->new( );
$browser->agent('Deloxom/1.0');
$browser->credentials($api_net_loc, $api_realm, $user => $pass);
my $response = $browser->get($api_url."/posts/get?dt=$date");
if ($response->is_success) {
return $response->content();
} else {
print $response->error_as_HTML();
die();
}
}
sub charData
{
#kill misc data
}
#xml handling subroutines
package SubHandlers;
sub post {
my $expat = shift; my $element = shift;
while (@_) {
my $att = shift;
my $val = shift;
$attr{$att} = $val;
}
####################
# LINK OUTPUT AREA #
####################
# add to output the link
$out .= "<li><a href=\"".$attr{'href'}."\">".$attr{'description'}."</a>";
# extended tag output:
if ($attr{'extended'}) {
$out .= "<blockquote>".$attr{'extended'}."</blockquote>";
undef $attr{'extended'};
}
$out .= "</li>";
# some other stuff you might be interested in:
#
# $attr{'time'} << timestamp like "2004-02-10T05:11:37Z"
# $attr{'tag'} << tags as a space-seperated list
#
}
sub post_ {
# by default nothing but put any formatting
# you want to appear after each post here
}
#EOF