-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,174 additions
and
133 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
MikuWeather_CS/.idea/.idea.MikuWeather/.idea/contentModel.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace MikuWeather | ||
{ | ||
internal static class DataQuery | ||
{ | ||
public static Dictionary<string, string> UpdateData_Baidu(string city) | ||
{ | ||
Dictionary<string, string> resultDict = new Dictionary<string, string>(); | ||
const string url = "http://api.map.baidu.com/telematics/v3/weather?location="; | ||
var key = ConfigurationManager.AppSettings["apikey_baidu"]; | ||
var requestUrl = url + city + "&output=json&ak=" + key; | ||
var request = (HttpWebRequest) WebRequest.Create(requestUrl); | ||
request.Method = "GET"; | ||
string result; | ||
try | ||
{ | ||
var response = (HttpWebResponse) request.GetResponse(); | ||
using (var reader = | ||
new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException(), | ||
Encoding.UTF8)) | ||
{ | ||
result = reader.ReadToEnd(); | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
resultDict.Add("Exception", exception.Message); | ||
return resultDict; | ||
} | ||
|
||
var resultJo = JObject.Parse(result); | ||
var status = (string) resultJo.SelectToken("error"); | ||
if (status != "0") | ||
{ | ||
resultDict.Add("Exception", "error code"); | ||
return resultDict; | ||
} | ||
var pm25Str = resultJo.SelectToken("pm25").ToString(); | ||
var resultToken = resultJo.SelectToken("results")[0]; | ||
var weatherToken = resultToken.SelectToken("weather_data"); | ||
return resultDict; | ||
} | ||
|
||
public static string GetLocation() | ||
{ | ||
const string url = "http://api.map.baidu.com/location/ip?ak="; | ||
var key = ConfigurationManager.AppSettings["apikey_baidu"]; | ||
var requestUrl = url + key; | ||
var request = (HttpWebRequest)WebRequest.Create(requestUrl); | ||
request.Method = "GET"; | ||
string result; | ||
try | ||
{ | ||
var response = (HttpWebResponse)request.GetResponse(); | ||
using (var reader = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException(), Encoding.UTF8)) | ||
{ | ||
result = reader.ReadToEnd(); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
return "Exception"; | ||
} | ||
var resultJo = JObject.Parse(result); | ||
var status = (string)resultJo.SelectToken("status"); | ||
if (status != "0") | ||
{ | ||
return "status code ≠ 0"; | ||
} | ||
var contentToken = resultJo.SelectToken("content").SelectToken("address_detail"); | ||
var cityToken = contentToken.SelectToken("city"); | ||
var cityName = cityToken.ToString().Split(Convert.ToChar("市"))[0]; | ||
return cityName; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,54 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace MikuWeather | ||
{ | ||
public partial class Form1 : Form | ||
{ | ||
// ReSharper disable once FieldCanBeMadeReadOnly.Local | ||
private readonly FormShow _frmShow = new FormShow(); | ||
|
||
public Form1() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void Form1_Load(object sender, EventArgs e) | ||
{ | ||
// throw new System.NotImplementedException(); | ||
BackColor = Color.FloralWhite; | ||
TransparencyKey = BackColor; | ||
|
||
var intScreenY = Screen.PrimaryScreen.WorkingArea.Bottom; | ||
|
||
SetBounds(Screen.PrimaryScreen.WorkingArea.Width - 272, | ||
intScreenY - Size.Height + 6, | ||
intScreenY - Size.Height + 13, | ||
Size.Width, Size.Height); | ||
var city = DataQuery.GetLocation(); | ||
MessageBox.Show(city); | ||
} | ||
|
||
private void Form1_MouseHover(object sender, EventArgs e) { | ||
_frmShow.SetBounds(Location.X - _frmShow.Width / 2 + Width / 2, | ||
Location.Y - _frmShow.Height, | ||
_frmShow.Width, | ||
_frmShow.Height); | ||
_frmShow.Show(); | ||
} | ||
|
||
private void Form1_MouseLeave(object sender, EventArgs e) { | ||
_frmShow.Hide(); | ||
} | ||
|
||
private void CmWebsite_Click(object sender, EventArgs e) | ||
{ | ||
Process.Start("https://github.com/RainySummerLuo/MikuWeather_Windows"); | ||
} | ||
|
||
private void CmExit_Click(object sender, EventArgs e) | ||
{ | ||
Close(); | ||
Environment.Exit(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.