Skip to content
Browse files

added initial files

  • Loading branch information...
0 parents commit d9614fb723d471f3b83ccc00501d7d8e4f1d2a22 @skidding committed Feb 26, 2012
255 cities.txt
@@ -0,0 +1,255 @@
+Honolulu
+
+ zone: -10
+
+ morning: aloha
+ afternoon: aloha
+ evening: aloha
+ night: aloha
+
+Vancouver
+
+ zone: -8
+
+ morning: good morning
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
+
+Los Angeles
+
+ zone: -8
+
+ morning: good morning
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
+
+Mexico City
+
+ zone: -6
+
+ morning: buenos días
+ afternoon: buenas tardes
+ evening: buenas noches
+ night: buenas noches
+
+New York
+
+ zone: -5
+
+ morning: good morning
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
+
+São Paulo
+
+ zone: -3
+
+ morning: bom dia
+ afternoon: bom tarde
+ evening: bom noite
+ night: bom noite
+
+Reykjavík
+
+ morning: Góðan dag
+ afternoon: Góðan dag
+ evening: gott kvöld
+ night: góða nótt
+
+London
+
+ morning: top of the morning
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
+
+Barcelona
+
+ zone: 1
+
+ morning: buenos días
+ afternoon: buenas tardes
+ evening: buenas noches
+ night: buenas noches
+
+Paris
+
+ zone: 1
+
+ morning: bonjour
+ afternoon: bonjour
+ evening: bonsoir
+ night: bonne nuit
+
+Amsterdam
+
+ zone: 1
+
+ morning: goedemorgen
+ afternoon: goedemiddag
+ evening: goedenavond
+ night: goedenacht
+
+Venice
+
+ zone: 1
+
+ morning: buongiorno
+ afternoon: buon pomeriggio
+ evening: buonasera
+ night: buonanotte
+
+Berlin
+
+ zone: 1
+
+ morning: guten Morgen
+ afternoon: guten Tag
+ evening: guten Abend
+ night: guten Nacht
+
+Stockholm
+
+ zone: 1
+
+ morning: god morgon
+ afternoon: god ettermiddag
+ evening: god kveld
+ night: god natt
+
+Cape Town
+
+ zone: 2
+
+ morning: goeie môre
+ afternoon: goeie middag
+ evening: goeie aand
+ night: goeie nag
+
+Athens
+
+ zone: 2
+
+ morning: καλημέρα
+ afternoon: καλημέρα
+ evening: καλησπέρα
+ night: καληνύχτα
+
+Bucharest
+
+ zone: 2
+
+ morning: neața
+ afternoon: bună ziua
+ evening: bună seara
+ night: noapte bună
+
+Istanbul
+
+ zone: 2
+
+ morning: sabah iyi
+ afternoon: iyi akşamlar
+ evening: iyi geceler
+ night: iyi geceler
+
+Moscow
+
+ zone: 4
+
+ morning: доброе утро
+ afternoon: добрый день
+ evening: добрый вечер
+ night: спокойной ночи
+
+Dubai
+
+ zone: 4
+ font: arial.ttf
+ side: right
+
+ morning: صباح الخير
+ afternoon: ليلة سعيدة
+ evening: مساء الخير.
+ night: ليلة سعيدة
+
+Mumbai
+
+ zone: 5.5
+ font: mangal.ttf
+
+ morning: सुप्रभात
+ afternoon: नमस्कार
+ evening: गुड ईवनिंग.
+ night: शुभ रात्रि
+
+Bangkok
+
+ zone: 7
+ font: garunda.ttf
+
+ morning: ดีตอนเช้า
+ afternoon: สวัสดี
+ evening: สวัสดี
+ night: ราตรีสวัสดิ์
+
+Singapore
+
+ zone: 8
+
+ morning: good morning
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
+
+Hong Kong
+
+ zone: 8
+ font: simsun.ttc
+
+ morning: 早安
+ afternoon: 下午好
+ evening: 晚上好
+ night: 晚安
+
+Seoul
+
+ zone: 9
+ font: UnBatangOdal.ttf
+
+ morning: 아침 인사
+ afternoon: 안녕하세요
+ evening: 안녕하세요
+ night: 안녕히 주무세요
+
+Tokyo
+
+ zone: 9
+ font: simsun.ttc
+
+ morning: おはようございます
+ afternoon: こんにちは
+ evening: こんばんは
+ night: おやすみ
+
+Sydney
+
+ zone: 10
+
+ morning: good morning
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
+
+Fiji
+
+ zone: 12
+ city: Suva
+
+ morning: ni sa yadra
+ afternoon: good afternoon
+ evening: good evening
+ night: good night
225 city.php
@@ -0,0 +1,225 @@
+<?php
+
+class City
+{
+ public static $timeline = array
+ (
+ 0 => 'night',
+ 5 => 'morning',
+ 12 => 'afternoon',
+ 17 => 'evening',
+ 22 => 'night'
+ );
+
+ public static function get($file)
+ {
+ if(!file_exists($file))
+ {
+ return false;
+ }
+ $cities = array();
+
+ $rows = explode("\n", file_get_contents($file));
+
+ $city = null;
+
+ foreach($rows as $row)
+ {
+ if(trim($row) == '')
+ {
+ continue;
+ }
+ if(substr($row, 0, 1) == "\t")
+ {
+ list($key, $value) = explode(':', trim($row));
+
+ $city->$key = trim($value);
+
+ continue;
+ }
+ $cities[] = $city = new City($row);
+ }
+ return self::sort($cities);
+ }
+ public static function sort($cities)
+ {
+ $first = -1;
+
+ foreach($cities as $k => $city)
+ {
+ if($city->get_period() == 'morning')
+ {
+ $first = $k;
+
+ break;
+ }
+ }
+ $before = array_slice($cities, 0, $first);
+ $after = array_slice($cities, $first);
+
+ return array_merge($after, $before);
+ }
+
+ public $name;
+ public $zone;
+ public $city;
+
+ public $font;
+ public $side;
+
+ public $morning;
+ public $afternoon;
+ public $evening;
+ public $night;
+
+ public $woeid;
+ public $sunrise;
+ public $sunset;
+
+ public function __construct($name)
+ {
+ $this->name = $name;
+ $this->zone = 0;
+
+ $this->font = 'OpenSans-Regular.ttf';
+ $this->side = 'left';
+
+ $this->messages = new stdClass();
+ }
+
+ public function get_light()
+ {
+ if(!$this->get_woeid())
+ {
+ return 1;
+ }
+ $url = sprintf
+ (
+ 'http://weather.yahooapis.com/forecastrss?w=%d&u=c', $this->woeid
+ );
+ if(!$contents = file_get_contents($url))
+ {
+ return 1;
+ }
+ if(!preg_match('/sunrise="(.*?)"/', $contents, $matches))
+ {
+ return 1;
+ }
+ $this->sunrise = $this->get_minutes_from_text($matches[1]);
+
+ if(!preg_match('/sunset="(.*?)"/', $contents, $matches))
+ {
+ return 1;
+ }
+ $this->sunset = $this->get_minutes_from_text($matches[1]);
+
+ $current = $this->get_hour() * 60 + (int)date('i');
+
+ $A = 120;
+ $B = $A * 2;
+
+ if($current <= $this->sunrise - $A || $current >= $this->sunset + $A)
+ {
+ return 0;
+ }
+ if($current >= $this->sunrise + $A && $current <= $this->sunset - $A)
+ {
+ return 1;
+ }
+ if($current < $this->sunrise)
+ {
+ return ($A - ($this->sunrise - $current)) / $B;
+ }
+ if($current < $this->sunrise + $A)
+ {
+ return ($current - $this->sunrise) / $B + 0.5;
+ }
+ if($current < $this->sunset)
+ {
+ return ($this->sunset - $current) / $B + 0.5;
+ }
+ return 0.5 - ($current - $this->sunset) / $B;
+ }
+
+ public function get_woeid()
+ {
+ if($this->woeid)
+ {
+ return $this->woeid;
+ }
+ $city = $this->city ? $this->city : $this->name;
+
+ $query = urlencode(sprintf
+ (
+ 'select * from geo.places where text="%s"', $city
+ ));
+ $url = sprintf
+ (
+ 'http://query.yahooapis.com/v1/public/yql?q=%s&format=xml', $query
+ );
+ if(!$contents = file_get_contents($url))
+ {
+ return false;
+ }
+ $xml = new SimpleXMLElement($contents);
+
+ foreach($xml->results->place as $k => $place)
+ {
+ if($place->placeTypeName == 'Town')
+ {
+ return $this->woeid = $place->woeid;
+ }
+ }
+ return false;
+ }
+
+ public function get_message()
+ {
+ $period = $this->get_period();
+
+ if(isset($this->$period))
+ {
+ return $this->$period;
+ }
+ return 'hello';
+ }
+
+ public function get_period()
+ {
+ $hour = $this->get_hour();
+
+ $period = 'night';
+
+ foreach(self::$timeline as $h => $p)
+ {
+ if($h > $hour)
+ {
+ break;
+ }
+ $period = $p;
+ }
+ return $period;
+ }
+
+ public function get_hour()
+ {
+ $diff = $this->zone - floor($this->zone);
+
+ $hour = (date('G') + floor($this->zone) + 24) % 24;
+
+ return $hour + $diff;
+ }
+
+ private function get_minutes_from_text($text)
+ {
+ $hour = preg_replace('/[^0-9:]/', '', $text);
+
+ list($hours, $minutes) = explode(':', $hour);
+
+ if(strpos($text, 'pm') !== false)
+ {
+ $hours += 12;
+ }
+ return $hours * 60 + $minutes;
+ }
+}
BIN fonts/OpenSans-Bold.ttf
Binary file not shown.
BIN fonts/OpenSans-BoldItalic.ttf
Binary file not shown.
BIN fonts/OpenSans-ExtraBold.ttf
Binary file not shown.
BIN fonts/OpenSans-ExtraBoldItalic.ttf
Binary file not shown.
BIN fonts/OpenSans-Italic.ttf
Binary file not shown.
BIN fonts/OpenSans-Light.ttf
Binary file not shown.
BIN fonts/OpenSans-LightItalic.ttf
Binary file not shown.
BIN fonts/OpenSans-Regular.ttf
Binary file not shown.
BIN fonts/OpenSans-Semibold.ttf
Binary file not shown.
BIN fonts/OpenSans-SemiboldItalic.ttf
Binary file not shown.
BIN fonts/UnBatangOdal.ttf
Binary file not shown.
BIN fonts/andlso.ttf
Binary file not shown.
BIN fonts/arabtype.ttf
Binary file not shown.
BIN fonts/arial.ttf
Binary file not shown.
BIN fonts/garunda.ttf
Binary file not shown.
BIN fonts/mangal.ttf
Binary file not shown.
BIN fonts/simsun.ttc
Binary file not shown.
63 index.php
@@ -0,0 +1,63 @@
+<?php
+
+include('city.php');
+
+// Init
+
+date_default_timezone_set('Europe/London');
+
+// Cities
+
+$cities = City::get('cities.txt');
+
+// Img
+
+$img = imagecreatetruecolor(800, count($cities) * 72 + 15);
+
+// Background
+
+$bg = imagecolorallocate($img, 11, 11, 11);
+
+imagefill($img, 0, 0, $bg);
+
+// Font
+
+$bold_font = 'OpenSans-Bold.ttf';
+$light_font = 'OpenSans-Light.ttf';
+
+$m_size = 15;
+$c_size = 22;
+
+// Text
+
+$i = 0;
+
+foreach($cities as $city)
+{
+ $light = $city->get_light();
+
+ $w = 75 + (180 * $light);
+ $g = 75 + (150 * $light);
+
+ $white = imagecolorallocate($img, $w, $w, $w);
+ $gray = imagecolorallocate($img, $g, $g, $g);
+ $dark = imagecolorallocate($img, 75, 75, 75);
+
+ $offset = $i++ * 72;
+
+ imagettftext($img, $m_size, 0, 16, 30 + $offset, $gray, "fonts/{$city->font}", $city->get_message());
+ imagettftext($img, $c_size, 0, 15, 62 + $offset, $dark, "fonts/$light_font", '#');
+ imagettftext($img, $c_size, 0, 35, 62 + $offset, $white, "fonts/$bold_font", $city->name);
+}
+
+// Header
+
+header('Content-Type: image/jpeg');
+
+// Print
+
+imagejpeg($img, null, 100);
+
+// Destroy
+
+imagedestroy($img);

0 comments on commit d9614fb

Please sign in to comment.
Something went wrong with that request. Please try again.