]> git.donarmstrong.com Git - bin.git/blob - jobs_to_org
update org files
[bin.git] / jobs_to_org
1 #!/usr/bin/perl
2 # SCRIPTNAME DOES_SOMETHING
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
5 # more information.
6 # Copyright 2016 by Don Armstrong <don@donarmstrong.com>.
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 SCRIPTNAME - DOES_SOMETHING
18
19 =head1 SYNOPSIS
20
21 SCRIPTNAME [options]
22
23  Options:
24    --debug, -d debugging level (Default 0)
25    --help, -h display this help
26    --man, -m display manual
27
28 =head1 OPTIONS
29
30 =over
31
32 =item B<--debug, -d>
33
34 Debug verbosity. (Default 0)
35
36 =item B<--help, -h>
37
38 Display brief usage information.
39
40 =item B<--man, -m>
41
42 Display this manual.
43
44 =back
45
46 =head1 EXAMPLES
47
48 SCRIPTNAME
49
50 =cut
51
52 use OSSP::uuid;
53 use WWW::Mechanize;
54 use WWW::Mechanize::TreeBuilder;
55 use vars qw($DEBUG);
56 use Data::Printer;
57 use Text::Wrap;
58
59 tie my $uuid, 'OSSP::uuid::tie';
60 $uuid= ["v1"];
61
62 my %options = (debug           => 0,
63                help            => 0,
64                man             => 0,
65                pages           => 1,
66                site            => 'herc',
67               );
68
69 GetOptions(\%options,
70            'site|s=s',
71            'pages|p=i',
72            'debug|d+','help|h|?','man|m');
73
74 pod2usage() if $options{help};
75 pod2usage({verbose=>2}) if $options{man};
76
77 $DEBUG = $options{debug};
78
79 my @USAGE_ERRORS;
80 # if (1) {
81 #     push @USAGE_ERRORS,"You must pass something";
82 # }
83
84 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
85
86 my %sites =
87     (herc => {url => 'http://main.hercjobs.org/jobs/search?keywords=professor+AND+%28genomics+OR+bioinformatics+OR+biology+OR+informatics%29&discipline=academic-faculty&category=academic-faculty&category=allied-health&category=biological-biomedical-sciences&category=computer-information-sciences&category=education&category=interdisciplinary&category=mathematics-statistics&category=medical-research&category=physical-sciences&sort=DATE_POSTED+DESC',
88               next_selector => [class => "bti-pagination-previous-link bti-pagination-prev-next",text => '>'],
89               job_selector => [url_regex => qr{^\/jobs\/\d+/.+}],
90               university => [itemprop=>"hiringOrganization",itemtype=>"http://schema.org/Organization"],
91               description => [class=>"bti-jd-description",itemprop=>"description"],
92               date => [class=>"bti-jd-detail-text",
93                        sub {scalar $_[0]->parent()->attr('class') eq 'bti-jd-details-action'}],
94               position => [class=>"bti-jd-title",itemprop=>"title"],
95              },
96     );
97
98 binmode STDOUT,":utf8";
99 get_jobs($options{site},$options{pages});
100 sub get_jobs {
101     my ($site,$pages) = @_;
102
103     my $m = WWW::Mechanize->new();
104     WWW::Mechanize::TreeBuilder->meta->apply($m);
105     if (not defined $sites{$site}) {
106         die "Unknown site $site";
107     }
108     my $s = $sites{$site};
109     $m->get($s->{url});
110     for (1..$pages) {
111         my %seen;
112         my @job_urls = grep { ! $seen{ $_->URI()->abs() }++ }
113             $m->find_all_links(@{$s->{job_selector}});
114         for my $j_u (@job_urls) {
115             $m->get($j_u);
116             my $university = $m->tree->look_down(@{$s->{university}})->as_text();
117             my $date = $m->tree->look_down(@{$s->{date}})->as_text();
118             my $description = $m->tree->look_down(@{$s->{description}})->as_text();
119             my $position = $m->tree->look_down(@{$s->{position}})->as_text();
120             print format_job($university,$position,$j_u->URI->abs(),$description,$date);
121             $m->back();
122         }
123         $m->follow_link(@{$s->{next_selector}}) or die "Unable to find next link";
124     }
125 }
126
127 sub format_job {
128     my ($university,$position,$url,$text,$date) = @_;
129     $text = wrap('   ','   ',$text);
130     my $ret = <<"EOF";
131 ** TODO $university -- $position
132    :PROPERTIES:
133    :ID:       $uuid
134    :END:
135 [[$url]]
136 [$date]
137
138 $text
139
140 EOF
141     return $ret;
142 }
143
144
145
146 __END__