SampleTest.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package org.jeecg;
  2. import cn.com.ctop.common.module.entity.BindAccountLogin;
  3. import cn.com.ctop.common.module.entity.CtopOauthToken;
  4. import cn.com.ctop.common.module.service.IBindAccountLoginService;
  5. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  6. import cn.com.ctop.common.module.utils.CtopAdConstant;
  7. import cn.com.ctop.common.module.utils.HttpUtils;
  8. import cn.com.ctop.crawler.modules.pangolin.entity.PangolinApp;
  9. import cn.com.ctop.crawler.modules.pangolin.service.PangolinAppService;
  10. import cn.com.ctop.crawler.modules.pangolin.service.PangolinCrawlerService;
  11. import cn.com.ctop.crawler.modules.pangolin.service.PangolinLoginService;
  12. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
  13. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  14. import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
  15. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  16. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  17. import com.alibaba.fastjson.JSONArray;
  18. import com.alibaba.fastjson.JSONObject;
  19. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  20. import lombok.extern.slf4j.Slf4j;
  21. import org.jeecg.common.util.DateUtils;
  22. import org.junit.Test;
  23. import org.junit.runner.RunWith;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.boot.test.context.SpringBootTest;
  26. import org.springframework.test.context.junit4.SpringRunner;
  27. import java.util.Date;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.concurrent.CountDownLatch;
  32. import java.util.concurrent.ExecutorService;
  33. import java.util.concurrent.Executors;
  34. @RunWith(SpringRunner.class)
  35. @SpringBootTest
  36. @Slf4j
  37. public class SampleTest {
  38. @Autowired
  39. private IBytedanceReportService bytedanceReportService;
  40. @Autowired
  41. private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
  42. @Autowired
  43. private ICtopOauthTokenService oauthTokenService;
  44. @Autowired
  45. private IReportService reportService;
  46. @Test
  47. public void testOceanEngineJob() {
  48. try {
  49. String url = "https://ad.e.kuaishou.com/rest/openapi/v1/tool/key_frame";
  50. JSONArray ptotoArr = new JSONArray();
  51. ptotoArr.add("5188991225263567823");
  52. Map<String, String> headers = new HashMap<>();
  53. headers.put("Access-Token", "e251db4aa139eb36623818581003bcec");
  54. headers.put("Content-Type", "application/json");
  55. JSONObject requestJson = new JSONObject();
  56. requestJson.put("advertiser_id", 161468);
  57. requestJson.put("photo_ids", ptotoArr);
  58. // requestJson.put("type", type);
  59. String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
  60. System.err.println(result);
  61. // CtopOauthToken byId = oauthTokenService.getById(1654059015242756L);
  62. /* SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  63. Date start = simpleDateFormat.parse("2020-01-01");
  64. Date end = simpleDateFormat.parse("2020-06-03");*/
  65. /*String nowDate = "2020-06-03";
  66. String endDate = "2020-01-01";
  67. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  68. Date start = simpleDateFormat.parse(nowDate);
  69. Date end = simpleDateFormat.parse(endDate);
  70. List<Date> dates = DateUtils.findDates(end, start);
  71. for (int i = 0; i < dates.size(); i++) {
  72. String formatDate = simpleDateFormat.format(dates.get(i));
  73. Date parse = simpleDateFormat.parse(formatDate);
  74. reportService.getAdvertiserReport(byId, parse, parse, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  75. }*/
  76. } catch (Exception e) {
  77. e.printStackTrace();
  78. }
  79. String account = "3248395570@qq.com";
  80. /* String password = "Ydxq-704127411";
  81. oceanEngineService.login(account,password);
  82. oceanEngineService.douyinHotHandler(1,1);
  83. oceanEngineService.effectCaseHandler(1);
  84. oceanEngineService.hotMaterialHandler(1,4,"抖音");
  85. oceanEngineService.hotMaterialHandler(1,8,"头条");
  86. oceanEngineService.hotMaterialHandler(1,1,"西瓜");
  87. oceanEngineService.hotMaterialHandler(1,3,"火山");
  88. oceanEngineService.hotMaterialHandler(1,9,"穿山甲");
  89. log.info("巨量创意抓取完成");*/
  90. }
  91. @Autowired
  92. private IBindAccountLoginService bindAccountLoginService;
  93. @Autowired
  94. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  95. @Test
  96. public void kuaishouLogin() {
  97. Long start = System.currentTimeMillis();
  98. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  99. if (list != null && !list.isEmpty()) {
  100. for (BindAccountLogin login : list) {
  101. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  102. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  103. }
  104. }
  105. }
  106. Long end = System.currentTimeMillis();
  107. log.info("总用时:{}毫秒", end - start);
  108. }
  109. static ExecutorService executorService = null;
  110. static CountDownLatch countDownLatch = null;
  111. @Test
  112. public void kuaishouCommentDelete() {
  113. Long start = System.currentTimeMillis();
  114. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  115. if (list != null && !list.isEmpty()) {
  116. executorService = Executors.newFixedThreadPool(10);
  117. countDownLatch = new CountDownLatch(list.size());
  118. list.forEach(login -> {
  119. executorService.submit(() -> {
  120. try {
  121. if (null != login.getCookie() && !"".equals(login.getCookie().trim())) {
  122. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  123. }
  124. } catch (Exception e) {
  125. } finally {
  126. countDownLatch.countDown();
  127. }
  128. });
  129. });
  130. }
  131. try {
  132. countDownLatch.await();
  133. } catch (InterruptedException e) {
  134. e.printStackTrace();
  135. }
  136. Long end = System.currentTimeMillis();
  137. log.info("总用时:{}毫秒", end - start);
  138. }
  139. @Autowired
  140. private PangolinLoginService pangolinLoginService;
  141. @Autowired
  142. private PangolinCrawlerService pangolinCrawlerService;
  143. @Autowired
  144. private PangolinAppService pangolinAppService;
  145. @Test
  146. public void testPangolinLogin() {
  147. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  148. queryWrapper.eq("login_type", "pangolin");
  149. queryWrapper.eq("status", 1);
  150. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  151. if (list != null && !list.isEmpty()) {
  152. for (BindAccountLogin login : list) {
  153. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  154. pangolinLoginService.pangolinLogin(login.getAccountName(), login.getPassword());
  155. }
  156. }
  157. }
  158. }
  159. @Test
  160. public void testPangolinData() {
  161. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  162. queryWrapper.eq("login_type", "pangolin");
  163. queryWrapper.eq("status", 1);
  164. queryWrapper.isNotNull("cookie");
  165. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  166. if (list != null && !list.isEmpty()) {
  167. for (BindAccountLogin bindAccountLogin : list) {
  168. pangolinCrawlerService.getChannelList(bindAccountLogin);
  169. pangolinCrawlerService.getActivationList(bindAccountLogin, DateUtils.getNowDate("yyyy-MM-dd"), 1);
  170. pangolinCrawlerService.getCheckList(bindAccountLogin);
  171. QueryWrapper<PangolinApp> queryWrapper1 = new QueryWrapper<>();
  172. queryWrapper1.eq("account_name", bindAccountLogin.getAccountName());
  173. List<PangolinApp> appList = pangolinAppService.list(queryWrapper1);
  174. if (appList != null && !appList.isEmpty()) {
  175. appList.forEach(pangolinApp -> pangolinCrawlerService.getRealTimeList(bindAccountLogin, pangolinApp.getId()));
  176. }
  177. }
  178. }
  179. }
  180. @Autowired
  181. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  182. @Test
  183. public void testLoadKuaishouData(){
  184. CtopOauthToken token = oauthTokenService.getTokenByAccountId(4801739L);
  185. for(int i=0;i<50;i++){
  186. Date startDate = DateUtils.addDay(new Date(),-(i+30));
  187. dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), DateUtils.formatDate(startDate));
  188. }
  189. }
  190. }