반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | package BoxOffice; import java.io.InputStream; import java.util.List; import javax.swing.JOptionPane; import com.google.gson.Gson; import study.java.helper.FileHelper; import study.java.helper.GsonHelper; import study.java.helper.HttpHelper; import study.java.model.BoxofficeBeans; import study.java.model.BoxofficeBeans.BoxOfficeResult; import study.java.model.BoxofficeBeans.BoxOfficeResult.DailyBoxOfficeList; /** * @file_name : Main.java * @author : 오태현 * @description : 검색날짜를 입력 받아 영화진흥위원회 API를 통해 일별박스오피스 검색결과를 csv형식 파일로 저장 * @last_update : 2018-12-18 */ public class Main { public static void main(String[] args) { String date = JOptionPane.showInputDialog("날짜(yyyymmdd)를 입력하세요. (당일 검색, 2002 이전 검색 불가)", "20181217"); String filePath = System.getProperty("user.home") + "\\Desktop\\박스오피스 ["+ date +"] 검색결과.csv"; InputStream is = HttpHelper.getInstance().getWebData("http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=6d2cf4aa96725383235c717f2e569f1e&targetDt=" + date, "UTF-8"); if (is == null) { System.out.println("데이터 다운로드 실패"); } String source = GsonHelper.getInstance().getGsonString(is, "UTF-8"); Gson g = new Gson(); BoxofficeBeans data = g.fromJson(source, BoxofficeBeans.class); BoxOfficeResult res = data.getBoxOfficeResult(); List<DailyBoxOfficeList> list = res.getDailyBoxOfficeList(); String line = "순 위,영화제목,개봉일,관람수\n"; for(int i =0 ; i<list.size(); i++) { DailyBoxOfficeList obj = list.get(i); line += obj; } FileHelper.getInstance().writeString(filePath, line, "EUC-KR"); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | package study.java.model; import java.util.List; import com.google.gson.annotations.SerializedName; /** * @file_name : BoxofficeBeans.java * @author : 오태현 * @description : 순위, 영화제목, 개봉일, 관람수를 기준으로하는 Beans 설정 * @last_update : 2018-12-18 */ public class BoxofficeBeans { @SerializedName("boxOfficeResult") private BoxOfficeResult boxOfficeResult; public BoxOfficeResult getBoxOfficeResult() { return boxOfficeResult; } public void setBoxOfficeResult(BoxOfficeResult boxOfficeResult) { this.boxOfficeResult = boxOfficeResult; } @Override public String toString() { return "" + boxOfficeResult; } public class BoxOfficeResult { @SerializedName("dailyBoxOfficeList") private List<DailyBoxOfficeList> dailyBoxOfficeList; public List<DailyBoxOfficeList> getDailyBoxOfficeList() { return dailyBoxOfficeList; } public void setDailyBoxOfficeList(List<DailyBoxOfficeList> dailyBoxOfficeList) { this.dailyBoxOfficeList = dailyBoxOfficeList; } @Override public String toString() { return "" + dailyBoxOfficeList; } public class DailyBoxOfficeList { @SerializedName("rank") private String rank; @SerializedName("movieNm") private String movieNm; @SerializedName("openDt") private String openDt; @SerializedName("audiCnt") private String audiCnt; public String getRank() { return rank; } public void setRank(String rank) { this.rank = rank; } public String getMovieNm() { return movieNm; } public void setMovieNm(String movieNm) { this.movieNm = movieNm; } public String getOpenDt() { return openDt; } public void setOpenDt(String openDt) { this.openDt = openDt; } public String getAudiCnt() { return audiCnt; } public void setAudiCnt(String audiCnt) { this.audiCnt = audiCnt; } @Override public String toString() { return rank + "," + movieNm + "," + openDt + "," + audiCnt + "\n"; } } } } | cs |
반응형
'코딩 예제' 카테고리의 다른 글
배열 원소들의 평균 (0) | 2018.12.16 |
---|---|
Calendar (0) | 2018.12.14 |
Kakao Book Search (0) | 2018.12.13 |
Random값의 범위 조절 (0) | 2018.12.12 |
로또번호 (0) | 2018.12.12 |