Esempio n. 1
0
    /// <summary>
    /// 時刻表csvを取得
    /// </summary>
    /// <param name="csv"></param>
    /// <param name="path"></param>
    /// <returns></returns>
    ///
    IEnumerator DownloadScheduleCsv(JikokuCsvData schedulecsv)
    {
        //var url = schedulecsv.csvpath.Replace("8080", "8084");
        string text = "";

        using (WWW www = new WWW(schedulecsv.csvpath))
        {
            yield return(www);

            if (www.error == null)
            {
                text = www.text;
            }
        }

        yield return(text);
    }
Esempio n. 2
0
    /// <summary>
    /// 時刻表
    /// </summary>
    /// <returns></returns>
    IEnumerator GetJikoku()
    {
        bool bret = true;

        if (jikokuflag == true)
        {
            WriteText(TextManager.Get(TextManager.KEY.DL_LOADING_1) + TextManager.Get(TextManager.KEY.JIKOKU) + TextManager.Get(TextManager.KEY.DL_LOADING_2) + "...");
            yield return(null);

            DeleteSql("train_schedule_info");

            List <JikokuCsvData> JiCsv = new List <JikokuCsvData>();
            var header = AddHeader();

            url = "https://trainposinfo.shinkeisei.co.jp/ShinkeiseiMobileWeb/webresources/jp.co.shinkeisei.entity.trainschedulecsv";

            WWW trainschedulewww = new WWW(url, null, header);
            yield return(trainschedulewww);

            if (trainschedulewww.error == null)
            {
                WriteText(TextManager.Get(TextManager.KEY.DL_UPDATING_1) + TextManager.Get(TextManager.KEY.JIKOKU) + TextManager.Get(TextManager.KEY.DL_UPDATING_2)
                          + "...\n" + TextManager.Get(TextManager.KEY.DL_WHILE));
                yield return(null);

                IList json = (IList)Json.Deserialize(trainschedulewww.text);
                foreach (IDictionary data in json)
                {
                    JikokuCsvData f = new JikokuCsvData();

                    f.filename = data["filename"].ToString();
                    f.csvpath  = data["csvpath"].ToString();

                    JiCsv.Add(f);
                }


                //string path = "";
                string text = "";
                foreach (JikokuCsvData schedulecsv in JiCsv)
                {
                    var download  = DownloadScheduleCsv(schedulecsv);
                    var coroutine = StartCoroutine(download);

                    yield return(coroutine);

                    text = (string)download.Current;
                }


                // 読み込み
                List <string> liststring = new List <string>();
                StringReader  csvReader  = new StringReader(text);
                if (csvReader != null)
                {
                    string record;

                    while (csvReader.Peek() > -1)
                    {
                        // 一行を取り出す
                        record = csvReader.ReadLine();

                        liststring.Add(record);
                    }
                }
                else
                {
                    Debug.Log("Error!");
                    Debug.Log(trainschedulewww.error);
                    ver_jikoku = client_v.train_schedule_info;
                    bret       = false;
                }
                text = "";


                query = "";
                for (int row = 0; row < liststring.Count; row++)
                {
                    string line = liststring[row];
                    if (row % 100 == 0)
                    {
                        WriteText(TextManager.Get(TextManager.KEY.DL_UPDATING_1) + TextManager.Get(TextManager.KEY.JIKOKU) + TextManager.Get(TextManager.KEY.DL_UPDATING_2)
                                  + "(" + (row + 1) + "/" + liststring.Count + ")\n" + TextManager.Get(TextManager.KEY.DL_WHILE));
                        yield return(null);

                        if (query != "")
                        {
                            try
                            {
                                query += ";";
                                sqlite.ExecuteNonQuery(query);
                            }
                            catch
                            {
                                Debug.Log("Error!");
                                Debug.Log(trainschedulewww.error);
                                ver_jikoku = client_v.train_schedule_info;
                                bret       = false;
                            }
                        }

                        query = "INSERT INTO train_schedule_info VALUES(" + line + ")";
                    }
                    else
                    {
                        query += ",(" + line + ")";
                    }
                }
                if (query != "")
                {
                    WriteText(TextManager.Get(TextManager.KEY.DL_UPDATING_1) + TextManager.Get(TextManager.KEY.JIKOKU) + TextManager.Get(TextManager.KEY.DL_UPDATING_2)
                              + "(" + liststring.Count + "/" + liststring.Count + ")\n" + TextManager.Get(TextManager.KEY.DL_WHILE));
                    yield return(null);

                    try
                    {
                        query += ";";
                        sqlite.ExecuteNonQuery(query);
                    }
                    catch
                    {
                        Debug.Log("Error!");
                        Debug.Log(trainschedulewww.error);
                        ver_jikoku = client_v.train_schedule_info;
                        bret       = false;
                    }
                }
                bret = true;
            }
            else
            {
                Debug.Log("Error!");
                Debug.Log(trainschedulewww.error);
                ver_jikoku = client_v.train_schedule_info;
                bret       = false;
            }
        }
        else
        {
            bret = true;
        }
        yield return(bret);
    }