about summary refs log tree commit diff stats
path: root/config.def.h
Commit message (Expand)AuthorAgeFilesLines
...
* some experimental state DO NOT USE THIS, I plan to have a nicer interface to ...Anselm R Garbe2008-03-141-3/+3
* some changes towards 4.9Anselm R Garbe2008-03-141-5/+8
* removed all defines of geoms, implemented setgeoms() instead, added config.an...Anselm R Garbe2008-03-131-34/+0
* changed config.def.hAnselm R Garbe2008-03-061-2/+2
* new stuffAnselm R Garbe2008-03-061-4/+6
* implemented setlayout in the way proposed on the ml, split tile() into two fu...Anselm R Garbe2008-03-061-17/+17
* changed config.def.hAnselm R Garbe2008-03-051-32/+9
* integrated the new -x -y -w toggles of dmenu into my setupAnselm R Garbe2008-03-051-1/+6
* implemented the stuff as I discussed on dwm@Anselm R Garbe2008-03-051-6/+55
* renamed maximise to monocle again.Anselm R Garbe2008-03-051-4/+2
* renamed MAXLEN into MAXTAGLEN (backward compliance)anselm@anselm12008-03-041-1/+1
* renamed monocle into maxmise, documented the keybindings in dwm(1)anselm@anselm12008-03-041-5/+7
* monocle goes mainstreamAnselm R Garbe2008-03-041-1/+3
* removed View cruft, now back to the rootsanselm@anselm12008-03-031-1/+0
* made tag names snappierAnselm R Garbe2008-02-291-1/+1
* removed initags -- we autoselect the first tag in each view insteadanselm@anselm12008-02-281-1/+0
* some more changes towards a better dwmAnselm R Garbe2008-02-281-1/+1
* proceeded, though we still miss a real Tag structanselm@anselm12008-02-271-2/+4
* disabled AIM_XINERAMAanselm@anselm12008-02-261-1/+1
* simplified dwmanselm@anselm12008-02-261-2/+2
* pushing my changes of tonight upstream (hg tip is NOW very UNSTABLE -- but th...anselm@anselm12008-02-231-7/+7
* changed arrange functions to contain the Monitor as first argumentAnselm R Garbe2008-02-211-1/+1
* proceeded with multihead/Xinerama supportanselm@anselm12007-12-221-5/+5
* removed maximize, there will be monocle soonanselm@anselm12007-12-221-1/+0
* fixed wrong tagging stuffanselm@anselm12007-12-221-1/+1
* added dmenu_run to config.hanselm@anselm12007-12-221-2/+1
* simplified Mod-mAnselm R. Garbe2007-12-091-1/+1
* implemented reapply for re-applying the tagging rules during runtime, Mod-rAnselm R. Garbe2007-12-081-0/+1
* Using a new tags definition (const char [][MAXTAGLEN] - thanks go to Szabolcs!Anselm R. Garbe2007-11-101-58/+57
* moved LENGTH to dwm.c, moved prevtags to dwm.carg@suckless.org2007-11-071-4/+0
* revival of RESIZEHINTSAnselm R. Garbe2007-11-021-0/+1
* replaced Nmacros with LENGTH(x) macroAnselm R. Garbe2007-10-281-6/+5
* replaced ISTILE with domwfact/dozoom bools, removed nrules, nlayouts and ltid...Anselm R. Garbe2007-10-281-1/+3
* going toward 4.7Anselm R. Garbe2007-10-271-0/+3
* removed RESIZEHINTS and enhanced tile for fixed or aspect-ratio'ed clientsarg@suckless.org2007-10-241-1/+0
* added antoszka's viewprev patch with some minor modifications, restored Clien...Anselm R. Garbe2007-10-101-0/+1
* removing NULL-terminating **tags definition in config.hAnselm R. Garbe2007-10-051-1/+1
* s/xterm/uxterm/Anselm R. Garbe2007-10-011-1/+1
* fixed font definitionAnselm R. Garbe2007-10-011-1/+1
* applied Peter Hartlich's border collapse patchAnselm R. Garbe2007-09-301-7/+7
* fixed colorsAnselm R. Garbe2007-09-271-3/+3
* updated with my favorite colorschemeAnselm R. Garbe2007-09-261-7/+6
* applied colors depend from lavishs proposalAnselm R. Garbe2007-09-251-6/+6
* switching to white normal bg, renaming tag 9 into www, for static use in conj...Anselm R. Garbe2007-09-231-9/+9
* renamed config.h into config.def.h, config.h will be created if not present, ...Anselm R. Garbe2007-09-231-0/+94
a>
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







                  

                       
                              

                                                                
 
                           

                                   
                                                     
 

                       


                                                     
                                                                    




                                            







                                              
                                                        




                                                                    
                                                          




                                                            


                                




                                      

                                                 







                                                              

                                         

                
                          
                                 

                                                                      
                 
                                














                                                                 


                                                        










                                                                     
                                     


                                                                    
                      







                                                                         
#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Tiny;
use JSON::MaybeXS;

use POSIX qw(strftime);

# For wrapping comment blocks.
use Unicode::LineBreak;
my $lb = Unicode::LineBreak->new(ColMax => 76); # Default is 76.

# Printing UTF-8 to STDOUT.
binmode(STDOUT, "encoding(UTF-8)");

die "usage: draco [-dv] <url>\n" unless scalar @ARGV;

my $DEBUG;
my $VERSION = "v0.1.3";
# Dispatch table to be parsed before url.
my %dispatch = (
    '-v'  => sub { print "Draco $VERSION\n"; exit; },
    '-d'  => sub { $DEBUG = 1; print STDERR "draco: debug on.\n"; },
);
if (exists $dispatch{$ARGV[0]}) {
    # shift @ARGV to get $url in next shift.
    $dispatch{shift @ARGV}->();
}

# $url contains the reddit post.
my $url = shift @ARGV;
my $json_url = "${url}.json";

my $http = HTTP::Tiny->new( verify_SSL => 1 );

# Fetch the post.
print STDERR "draco: fetching `$json_url'.\n" if $DEBUG;
my $response = $http->get($json_url);
die "Unexpected response - $response->{status}: $response->{reason}"
    unless $response->{success};

# Decode json.
print STDERR "draco: decoding json response.\n" if $DEBUG;
my $json_data = decode_json($response->{content});

# $post contains post data
my $post = $json_data->[0]->{data}->{children}->[0]->{data};

# Start the Org document.
print "#+", "STARTUP:content\n";

# Print the date.
my $date = strftime '%+', localtime();
print "#+", "DATE: $date\n";
print "\n";

# Print the post title & it's link.
print "* ", "[[$post->{url}][$post->{title}]]\n";

# Add various details to :PROPERTIES:.
print ":PROPERTIES:\n";
foreach my $detail (qw( subreddit created_utc author permalink
                        upvote_ratio ups downs score )) {
    print ":${detail}: =$post->{$detail}=\n"
        if scalar $post->{$detail};
}
# Include the archive date in properties.
print ":ARCHIVE_DATE: $date\n";
print ":END:\n";

# Add selftext if present.
print "\n#+BEGIN_SRC markdown\n",
    # Break the text at 76 column & add 2 space before every new line.
    "  ", $lb->break($post->{selftext}) =~ s/\n/\n\ \ /gr, "\n",
    "#+END_SRC\n"
    if scalar $post->{selftext};

# $comments contains comment data. We are interested in: replies,
# author, body, created_utc & permalink.
my $comments = $json_data->[1]->{data}->{children};
# Iterate over top-level comments.
foreach my $comment ($comments->@*) {
    print_comment_chain($comment->{data}, 0);
}

# print_comment_chain will print the whole chain of comment while
# accounting for level.
sub print_comment_chain {
    my $comment = shift @_;
    my $level = shift @_;

    print "*" x ($level + 2), " ", "$comment->{author}";
    print " [S]" if $comment->{is_submitter};
    print "\n";

    # Print comment details.
    print ":PROPERTIES:\n";
    foreach my $detail (qw( created_utc author permalink upvote_ratio
                            ups downs score edited is_submitter
                            stickied controversiality )) {
        print ":${detail}: =$comment->{$detail}=\n"
            if scalar $comment->{$detail};
    }
    print ":END:\n";

    print "\n#+BEGIN_SRC markdown\n",
        # Break the text at 76 column & add 2 space before every new
        # line.
        "  ", $lb->break($comment->{body}) =~ s/\n/\n\ \ /gr, "\n",
        "#+END_SRC\n";

    # If the comment has replies then iterate over those too.
    if (scalar $comment->{replies}) {
        foreach my $reply ($comment->{replies}->{data}->{children}->@*) {
            print_comment_chain($reply->{data}, $level + 1);
        }
    }
}