Attachment 'operators-parse.pl'

Download

   1 #!/usr/bin/perl
   2 
   3 use Locale::Country;
   4 
   5 sub text_linker {
   6 	# subrutin of printing texts
   7 	undef $kirak;
   8 	undef $po;
   9 	@l_temp=split /\*\*\*/, $_[0];
  10 	foreach (@l_temp) {
  11 		$po++;
  12 		$kirak.="$_$_[$po]";
  13 	}
  14 	return $kirak;
  15 }
  16 
  17 sub replace_country {
  18 	%replacements = (
  19 		"Lebannon", "Lebanon",
  20 		"Czech Rep.", "Czech Republic",
  21 		"Hong-Kong", "Hong Kong",
  22 		"UAE", "United Arab Emirates",
  23 		"Island", "Iceland",
  24 		"UK", "United Kingdom",
  25 		"Serbia-M.", "Serbia and Montenegro",
  26 		"Finlan", "Finland",
  27 		"St Vincent And The Grenadines", "Saint Vincent and the Grenadines",
  28 		"Moldavia", "Moldova",
  29 		"Macau, China", "China",	# Macau already in the provider name
  30 		"Laos", "Lao People's Democratic Republic",
  31 		"Serbia- Montenegro", "Serbia and Montenegro"
  32 
  33 	);
  34 	my $s = shift;
  35 
  36 	$replaced = $replacements{$s};
  37 	if ($replaced) {
  38 		$s = $replaced;
  39 	}
  40 	$retval = country2code($s);
  41 	$retval or return "unknown";
  42 	return $retval;
  43 }
  44 
  45 print "<gprs-operators>\n";
  46 
  47 open (FILE, "<apn");
  48 #open (FILE, "<small-apn");
  49 while ($read_line=<FILE>) {
  50 	$elsochar=substr ($read_line, 0, 1);
  51 	if ($elsochar ne "#" && $elsochar ne " " && $elsochar && $elsochar ne "\n") {
  52 		@apn_tomb=split/\t/,$read_line;
  53 		if ($apn_tomb[0] eq "0") { next };
  54 
  55 		%apn_subs = (
  56 			"31", "Dialog GSM (post-paid) (Sri Lanka)",
  57 			"279", "Dialog GSM (pre-paid) (Sri Lanka)",
  58 			"153", "T-Mobile (VoiceStream) (USA)",
  59 			"162", "Telekom Srbija (default) (Serbia-M.)",
  60 			"163", "Telekom Srbija (via MMS) (Serbia-M.)",
  61 			"164", "Telekom Srbija (via wap) (Serbia-M.)",
  62 			"178", "TIM (waptim) (Italy)",
  63 			"190", "VIPNET (PRO) (Croatia)",
  64 			"191", "VIPNET (START) (Croatia)",
  65 			"237", "VIPNET (3G) (Croatia)",
  66 			"263", "Djuice (Ukraine)"
  67 		);
  68 		if ($apn_subs{$apn_tomb[0]}) {
  69 			$apn_tomb[1] = $apn_subs{$apn_tomb[0]};
  70 		}
  71 
  72 		foreach (@apn_tomb) {chomp $_}
  73 		if (!$apn_tomb[3]) {$apn_tomb[3]="???"}
  74 		if (!$apn_tomb[4]) {$apn_tomb[4]="???"}
  75 		$apn_tomb[1]=~s /&/&amp;/;
  76 		$apn_tomb[3]=~s /\(\*\)/anything/;
  77 		$apn_tomb[4]=~s /\(\*\)/anything/;
  78 		$apn_tomb[3]=~s /\(\*{2}\)//;
  79 		$apn_tomb[4]=~s /\(\*{2}\)//;
  80 		$apn_tomb[3]=~s /\(\*{3}\)/text_linker($cl[87])/e;
  81 		$apn_tomb[4]=~s /\(\*{3}\)/text_linker($cl[87])/e;
  82 		$apn_tomb[3]=~s /\(\*{4}\)/text_linker($cl[87])/e;
  83 		$apn_tomb[4]=~s /\(\*{4}\)/text_linker($cl[87])/e;
  84 
  85 		$apn_tomb[2]=~ s/\s+$//;
  86 
  87 		@identifier=split/\(/,$apn_tomb[1];
  88 		$name = $identifier[0];
  89 		$name =~ s/\s+$//;
  90 
  91 		$country = $identifier[2];
  92 		$country =~s /\)//;
  93 		$country =~ s/\s+$//;
  94 
  95 		$type = $identifier[1];
  96 		$type =~s /\)//;
  97 		$type =~ s/\s+$//;
  98 
  99 		if ($country eq "") {
 100 			$country = $type;
 101 			$type = "";
 102 		}
 103 
 104 		$new_country = replace_country($country);
 105 		if ($new_country eq "unknown") {
 106 			($type, $country) = ($country, $type);
 107 			$new_country = replace_country($country);
 108 
 109 			$new_country ne "unknown" or die "Unknown countries '$type' and '$country' for id $apn_tomb[0]";
 110 		}
 111 		$country = $new_country;
 112 
 113 		print "\t<operator>\n";
 114 		print "\t\t<id>$apn_tomb[0]</id>\n";
 115 		print "\t\t<name>$name</name>\n";
 116 		print "\t\t<country>$country</country>\n";
 117 		if ($type ne "") {
 118 			print "\t\t<type>$type</type>\n";
 119 		}
 120 		if ($apn_tomb[2] ne "") {
 121 			print "\t\t<apn>$apn_tomb[2]</apn>\n";
 122 		}
 123 		if ($apn_tomb[3] ne "anything") {
 124 			print "\t\t<username>$apn_tomb[3]</username>\n";
 125 		}
 126 		if ($apn_tomb[4] ne "anything") {
 127 			print "\t\t<password>$apn_tomb[4]</password>\n";
 128 		}
 129 		print "\t\t<dns-servers>\n";
 130 		print "\t\t\t<dns>$apn_tomb[5]</dns>\n";
 131 		if ($apn_tomb[6] ne "") {
 132 			print "\t\t\t<dns>$apn_tomb[6]</dns>\n";
 133 		}
 134 		print "\t\t</dns-servers>\n";
 135 		print "\t</operator>\n";
 136 	}
 137 }
 138 
 139 print "</gprs-operators>\n";

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-05-05 11:20:49, 3.5 KB) [[attachment:operators-parse.pl]]
  • [get | view] (2008-05-05 11:19:27, 82.0 KB) [[attachment:operators.xml]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.