예제 #1
0
 public void DeleteBook(int id)
 {
     Newtonsoft.Json.Linq.JArray books = connector.GetInfo();
     Newtonsoft.Json.Linq.JToken jt    = books.Where(b => b["id"].ToObject <int>().Equals(id)).First();
     books.Remove(jt);
     connector.WriteInfo(books);
 }
예제 #2
0
        public Book GetBook(int id)
        {
            Newtonsoft.Json.Linq.JArray books = connector.GetInfo();
            Book book;

            book = books.Where(b => b["id"].ToObject <int>().Equals(id)).First().ToObject <Book>();
            return(book);
        }
예제 #3
0
 public void UpdateBook(int id, string name, string author, int pages, int count, int edition)
 {
     Newtonsoft.Json.Linq.JArray books = connector.GetInfo();
     Newtonsoft.Json.Linq.JToken jt    = books.Where(b => b["id"].ToObject <int>().Equals(id)).First();
     jt["name"]    = name;
     jt["author"]  = author;
     jt["pages"]   = pages;
     jt["count"]   = count;
     jt["edition"] = edition;
     connector.WriteInfo(books);
 }
예제 #4
0
        public void Update(Newtonsoft.Json.Linq.JArray pages, Guid userId, TakeDocModel.Version version, Guid entityId)
        {
            TakeDocModel.TypeDocument typeDoc = daoTypeDocument.GetBy(x => x.TypeDocumentId == version.Document.DocumentTypeId).First();

            if (typeDoc.TypeDocumentPageNeed)
            {
                int nb = pages.Where(obj => obj.Value <string>("pageNumber") != "-1").Count();
                if (nb == 0)
                {
                    throw new Exception("Une photographie est obligatoire.");
                }
            }

            foreach (Newtonsoft.Json.Linq.JObject page in pages.OrderBy(obj => obj["pageNumber"]))
            {
                Guid id = Guid.Empty;
                try
                {
                    id = new Guid(page.Value <string>("id"));
                }
                catch (Exception ex)
                {
                    id = Guid.Empty;
                }

                int    rotation   = page.Value <int>("rotation");
                int    pageNumber = page.Value <int>("pageNumber");
                string action     = page.Value <string>("action");
                if (string.IsNullOrEmpty(action) == false)
                {
                    bool delete = action.ToUpper().Equals("DELETE");
                    bool add    = action.ToUpper().Equals("ADD");
                    bool update = action.ToUpper().Equals("UPDATE");
                    if (delete && id != Guid.Empty)
                    {
                        this.Update(id, rotation, pageNumber, delete, userId, entityId);
                    }
                    else if (add)
                    {
                        string extension = page.Value <string>("base64Image").Split(';')[0].Replace("data:image/", string.Empty);
                        this.Add(userId, entityId, version.VersionId, page.Value <string>("base64Image"), extension, rotation, pageNumber);
                    }
                    else if (update && id != Guid.Empty)
                    {
                        this.Update(id, rotation, pageNumber, delete, userId, entityId);
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 영화 API 스캔
        /// </summary>
        private void movie()
        {
            History      history      = new History(kobisInfo.RootDir);
            UrlGenerator urlGenerator = new UrlGenerator();

            string kobiskey  = kobisInfo.Key;
            string tmdbkey   = tmdbInfo.Key;
            string pageindex = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_PAGEINDEX];
            string viewcount = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_VIEWCOUNT];
            string startdt   = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_STARTDT];
            string enddt     = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_ENDDT];

            List <string> crawledData = history.getCrawledDataList();

            history.backupFile();
            history.createFile();

            Console.Write("[info] kobis api reading...");
            XDocument xDoc = XDocument.Load(
                urlGenerator.movieListAPI(
                    kobisInfo.Services[Constant.ApiList.MOVIE_LIST],
                    kobiskey, pageindex, viewcount, startdt, enddt
                    )
                );

            Console.WriteLine("[OK][{0}]", DateTime.Now.ToString("yyyymmddhhmmss"));

            var root      = xDoc.Descendants("movieListResult");
            var movieList = root.Descendants("movieList").Descendants("movie").Select(m => m);

            XElement movieXml = new XElement("root");

            List <string> kobisList = new List <string>();

            foreach (var movie in movieList)
            {
                string movieCd = movie.Element("movieCd").Value;
                kobisList.Add(movieCd);
            }

            Console.Write("[info] filtering exist data...");
            List <string> newItem = kobisList.AsParallel()
                                    .Where(code => !crawledData.Contains(code))
                                    .ToList();

            Console.WriteLine("[OK][{0}]", DateTime.Now.ToString("yyyymmddhhmmss"));

            Console.Write("[info] target data [{0}] counts", newItem.Count);
            foreach (var item in newItem)
            {
                history.writeInFile(item);

                #region MOVIE_DETAIL
                xDoc = XDocument.Load(
                    urlGenerator.movieInfoAPI(
                        kobisInfo.Services[Constant.ApiList.MOVIE_DETAIL],
                        kobiskey, item
                        )
                    );

                var movieInfo = xDoc.Descendants("movieInfoResult").Descendants("movieInfo").Select(info => info).First();

                string movieCd   = Utils.XmlUtil.getElementValue(movieInfo.Element("movieCd"), "");
                string movieNm   = Utils.XmlUtil.getElementValue(movieInfo.Element("movieNm"), "");
                string movieNmEn = Utils.XmlUtil.getElementValue(movieInfo.Element("movieNmEn"), "");
                string movieNmOg = Utils.XmlUtil.getElementValue(movieInfo.Element("movieNmOg"), "");
                string showTm    = Utils.XmlUtil.getElementValue(movieInfo.Element("showTm"), "0");
                string openDt    = Utils.XmlUtil.getElementValue(movieInfo.Element("openDt"), "미개봉");
                string genres    = string.Join(",", movieInfo.Element("genres")
                                               .Elements("genre")
                                               .Select(genre =>
                                                       Utils.XmlUtil.getElementValue(genre.Element("genreNm"), "")
                                                       )
                                               );
                string audits = Utils.StringUtil.replaceNullOrEmpty(
                    movieInfo.Element("audits")
                    .Elements("audit")
                    .Select(audit =>
                            Utils.XmlUtil.getElementValue(audit.Element("watchGradeNm"), "")
                            ).FirstOrDefault()
                    , "");
                string isAdult = (audits == "" || audits != "청소년관람불가") ? "N" : "Y";
                string nations = Utils.StringUtil.replaceNullOrEmpty(
                    movieInfo.Element("nations")
                    .Elements("nation")
                    .Select(nation =>
                            Utils.XmlUtil.getElementValue(nation.Element("nationNm"), "")
                            ).FirstOrDefault()
                    , "");
                nations = (openDt != "미개봉") ? "한국" : nations;
                var directors = movieInfo.Element("directors")
                                .Elements("director")
                                .Select(director =>
                                        Utils.XmlUtil.getElementValue(director.Element("peopleNm"), "")
                                        );
                var actors = movieInfo.Element("actors")
                             .Elements("actor")
                             .Select(actor =>
                                     Utils.XmlUtil.getElementValue(actor.Element("peopleNm"), "")
                                     );
                #endregion

                #region PEOPLE_DETAIL
                xDoc = XDocument.Load(
                    urlGenerator.peopleInfoAPI(
                        kobisInfo.Services[Constant.ApiList.PEOPLE_LIST],
                        kobiskey,
                        movieNm
                        )
                    );

                var peopleList = xDoc.Descendants("peopleListResult").Descendants("peopleList").Descendants("people").Select(info => info);

                string directorsCd = string.Join(",", peopleList.Where(p =>
                                                                       p.Element("repRoleNm").Value == "감독" &&
                                                                       directors.Contains(p.Element("peopleNm").Value)
                                                                       )
                                                 .Select(p =>
                                                         Utils.XmlUtil.getElementValue(p.Element("peopleCd"), "")
                                                         )
                                                 );
                string actorsCd = string.Join(",", peopleList.Where(p =>
                                                                    p.Element("repRoleNm").Value == "배우" &&
                                                                    actors.Contains(p.Element("peopleNm").Value)
                                                                    )
                                              .Select(p =>
                                                      Utils.XmlUtil.getElementValue(p.Element("peopleCd"), "")
                                                      )
                                              );
                #endregion

                #region TMDB_SEARCH
                System.Net.WebClient client = new System.Net.WebClient();
                client.Encoding = System.Text.Encoding.UTF8;

                var json = client.DownloadString(
                    urlGenerator.tmdbInfoAPI(
                        tmdbInfo.Services[Constant.ApiList.MOVIE_LIST],
                        tmdbkey, movieNm, movieNmEn, openDt
                        )
                    );

                Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(json);

                int    tmdbKey   = 0;
                string overview  = string.Empty;
                string poster    = string.Empty;
                string thumbnail = string.Empty;

                int findCount = Convert.ToInt32(jObject["total_results"]);
                Newtonsoft.Json.Linq.JArray jResult = ((Newtonsoft.Json.Linq.JArray)jObject["results"]);

                dynamic results;
                if (findCount > 1)
                {
                    results = jResult.Where(result =>
                                            result["release_date"].ToString().Replace("-", "") == openDt.Replace("미개봉", "")
                                            )
                              .Select(result => result
                                      ).FirstOrDefault();
                }
                else if (findCount == 1)
                {
                    results = jResult.Select(result => result).FirstOrDefault();
                }
                else
                {
                    results = null;
                }

                if (results != null)
                {
                    tmdbKey   = (results["id"] != null) ? Convert.ToInt32(results["id"].ToString()) : 0;
                    overview  = (results["overview"] != null) ? results["overview"].ToString() : "";
                    poster    = (results["poster_path"] != null) ? results["poster_path"].ToString() : "";
                    thumbnail = (results["backdrop_path"] != null) ? results["backdrop_path"].ToString() : "";

                    poster    = (poster != "") ? tmdbInfo.PosterRootUrl + poster : "";
                    thumbnail = (thumbnail != "") ? tmdbInfo.ThumbnailRootUrl + thumbnail : "";

                    string path = string.Format("{0}\\{1}\\", tmdbInfo.DownloadPath, movieCd);

                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    using (System.Net.WebClient wc = new System.Net.WebClient())
                    {
                        if (poster.Trim() != "")
                        {
                            try
                            {
                                string filenm = poster.Substring(poster.LastIndexOf("/") + 1);
                                client.DownloadFile(new Uri(poster), path + filenm);
                                poster = poster.Replace(tmdbInfo.PosterRootUrl, string.Format("{0}/{1}", tmdbInfo.DownloadUrl, movieCd));
                            }
                            catch (System.Net.WebException)
                            {
                            }
                        }

                        if (thumbnail.Trim() != "")
                        {
                            try
                            {
                                string filenm = thumbnail.Substring(thumbnail.LastIndexOf("/"));
                                client.DownloadFile(new Uri(thumbnail), path + filenm);
                                thumbnail = thumbnail.Replace(tmdbInfo.ThumbnailRootUrl, string.Format("{0}/{1}", tmdbInfo.DownloadUrl, movieCd));
                            }
                            catch (System.Net.WebException)
                            {
                            }
                        }
                    }
                }
                #endregion

                movieXml.Add(
                    new XElement("movieList",
                                 new XElement("movieCd", movieCd),
                                 new XElement("movieNm", movieNm),
                                 new XElement("movieNmEn", movieNmEn),
                                 new XElement("movieNmOg", movieNmOg),
                                 new XElement("showTm", showTm),
                                 new XElement("openDt", openDt),
                                 new XElement("genres", genres),
                                 new XElement("audits", audits),
                                 new XElement("isAdult", isAdult),
                                 new XElement("nations", nations),
                                 new XElement("directors", directorsCd),
                                 new XElement("actors", actorsCd),
                                 new XElement("tmdbKey", tmdbKey),
                                 new XElement("overview", overview),
                                 new XElement("poster", poster),
                                 new XElement("thumbnail", thumbnail)
                                 )
                    );
                _scanCount++;
                printRealtimeCrawlCount();
            }
            history.closeFile();

            System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(string.Format("{0}\\crawled\\", kobisInfo.RootDir));

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            using (System.IO.StreamWriter record = new System.IO.StreamWriter(string.Format("{0}\\crawled\\{1}.xml", kobisInfo.RootDir, System.DateTime.Now.ToString("yyyyMMddhhmmss"))))
            {
                record.WriteLine(movieXml.ToString());
                record.Flush();
            }

            Console.WriteLine();
            Console.WriteLine("CRAWL COUNT : {0}", _scanCount);
        }