-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakeurl
More file actions
executable file
·59 lines (44 loc) · 1.3 KB
/
makeurl
File metadata and controls
executable file
·59 lines (44 loc) · 1.3 KB
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
#!/usr/bin/perl
# makeurl city search-terms
#
# ideas borrowed from
# https://moz.com/ugc/geolocation-the-ultimate-tip-to-emulate-local-search
# +-----------+------------------------------------------------------
# | Libraries |
# +-----------+
use MIME::Base64;
use URI::Encode qw(uri_encode);
# +-----------+------------------------------------------------------
# | Constants |
# +-----------+
# The list of codes for different length strings
my @CODES= split(//,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
# The start of the URL
my $BASE = "http://www.google.com/search?";
# +------+-----------------------------------------------------------
# | Main |
# +------+
# Grab the parameters
my $city = $ARGV[0];
my $term = $ARGV[1];
# Build the location part of the query
my $code = encode_base64($city);
chomp($code);
$code =~ s/==$//;
my $location = "uule=w+CAIQICI" . lengthcode($city) . $code;
# Build the term part of the query
my $search = "q=" . uri_encode($term);
# Build the whole URL
my $url = "$BASE$location&$search";
# And we're done
print "$url\n";
exit 0;
# +-------------+----------------------------------------------------
# | Subroutines |
# +-------------+
sub lengthcode($) {
my $string = shift;
my $length = length($string);
$length = $length % 64;
return $CODES[$length];
}