using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using System.Windows.Forms; using Newtonsoft.Json; namespace StationDataFileGenerator { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var targetDataFile = Path.Combine(_root, @"..\Web12306\js\station\station_data.js"); var inputDataFile = Path.Combine(_root, @"station_name.js"); var inputPopFile = Path.Combine(_root, @"favorite_name.js"); //常规数据 var commonDataText = File.ReadAllText(inputDataFile); var popDataText = File.ReadAllText(inputPopFile); //@bjb|北京北|VAP|beijingbei|bjb|0 //@bji|北京|BJP|0 var commonData = new Regex(@"@([a-z]+)\|([^\|]+)\|([^\|]+)\|([^\|@]+)\|([^\|@]+)\|([^\|@'""]+)", RegexOptions.IgnoreCase).Matches(commonDataText) .Cast().Select(s => new { p = s.Groups[4].Value.ToLower(), n = s.Groups[2].Value.ToLower(), c = s.Groups[3].Value, s = int.Parse(s.Groups[6].Value), h = s.Groups[5].Value.ToLower() }) .GroupBy(s => char.ToUpper(s.h[0])).ToDictionary(s => s.Key, s => s.OrderBy(x => x.s).ToDictionary(x => x.c)) ; var popData = new Regex(@"@([a-z]+)\|([^\|]+)\|([^\|]+)\|([^\|@]+)", RegexOptions.IgnoreCase).Matches(popDataText) .Cast().Select(s => s.Groups[3].Value).ToArray(); ; File.WriteAllText(targetDataFile, "define(function(require, exports, module){\r\n exports.data=" + Newtonsoft.Json.JsonConvert.SerializeObject(commonData) + ";\r\n exports.popcity=" + JsonConvert.SerializeObject(popData) + ";\r\n});"); Console.Write("OK."); Console.ReadKey(); } static string _root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } }