class Program
{
static void Main(string[] args)
{
try
{
decimal temperature = GetCurrentTemperature();
UpdateSignature(temperature);
Console.WriteLine(temperature);
}
catch (Exception e)
{
Console.WriteLine(e);
Environment.ExitCode = 1;
}
}
private static decimal GetCurrentTemperature()
{
var webClient = new WebClient();
webClient.Headers.Add("user-agent", "Mozilla");
string json = webClient.DownloadString("http://www.bom.gov.au/fwo/IDV60901/IDV60901.95936.json");
dynamic observations = new JavaScriptSerializer().DeserializeObject(json);
return observations["observations"]["data"][0]["air_temp"];
}
private static void UpdateSignature(decimal temperature)
{
const string SignatureFile = @"C:\Users\pchuchuv\AppData\Roaming\Microsoft\Signatures\Temperature.htm";
string signature = File.ReadAllText(SignatureFile);
string newSignature = Regex.Replace(signature, "Pavel<br>.*</p>",
string.Format("Pavel<br>{0}°</p>",
Math.Round(temperature, MidpointRounding.AwayFromZero)));
File.WriteAllText(SignatureFile, newSignature);
}
}
The program fetches the temperature from Australia’s Bureau of Meteorology (BOM) website.
I created a Visual Basic Script to run so that I don’t see a black console window every time the programs gets executed:
CreateObject("Wscript.Shell").Run "C:\etc\TemperatureToSignature.exe", 0, True
Open Outlook options, switch to Mail tab and click ‘Signatures’ button:
Create a new signature and give it ‘Temperature’ name. Edit the Temperature.htm file in C:\Users\<your username>\AppData\Roaming\Microsoft\Signatures folder and make sure it has this line:
<p class=MsoAutoSig>Pavel<br></p>
Don’t forget to change Pavel to your name 🙂
Next, open Task Scheduler.
- Create a new task
- Define a schedule to run every hour from 7:11
- Select .vbs file as ‘Program/script’
—
Pavel
15°