zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.gear.swx.task;
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.gear.swx.vo.SyncKValueFromLdVo;
import org.apache.logging.log4j.util.Strings;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.util.*;
 
public class test {
//    public static void main(String[] args) throws InterruptedException {
//        File file = new File("1.txt");
//        List<Map<String,Object>> result=  test.getInfo();
//        for(Map<String,Object> item : result){
//            String print = "{";
//            for(Map.Entry<String,Object> res:item.entrySet()){
//                String a=res.getKey();//获取当前map的键
//                Object b = res.getValue();
//                print = print + "\""+a+":\""+b+"\",";
//            }
//
//            System.out.print("}");
//            System.out.println();
//        }
//    }
//    public static List<Map<String,Object>> getInfo() throws InterruptedException {
//        List<Map<String,Object>> result = new ArrayList<>();
//        for (int i = 0;i < 10 ;i++){
//            Thread.sleep(2000);
//            List<Map<String,Object>> currentReuslt = new ArrayList<>();
//            try {
//                String urlStr = "https://data.mifengcha.com/api/v3/symbols?api_key=OQIYNHXPRLEA3GSP9JCVBMUHI614XOMXPJMROQGS&size=100&details=0&page="+i;
//                URL url = new URL(urlStr);
//                String ids = "";
//                // 创建 HTTP 连接
//                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//                connection.setRequestMethod("GET");
//
//                // 获取输入流
//                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//                // 读取 CSV 数据
//                String line;
//                StringBuilder response  = new StringBuilder();
//                while ((line = reader.readLine()) != null) { // 打印每一行数据
//                    response.append(line);
//                }
//                String reponseStr = response.toString();
//                JSONArray jsonArray = JSON.parseArray(reponseStr);
//                for(int j = 0; j < jsonArray.size(); j++){
//                  JSONObject jsonObject = jsonArray.getJSONObject(j);
//                  Map<String,Object> currentMap = new HashMap<>();
//                  currentMap.put("code",jsonObject.get("slug"));
//                  currentMap.put("name",jsonObject.get("symbol"));
//                  currentMap.put("logo",jsonObject.get("logoUrl"));
//                  ids = ids + "," + jsonObject.getString("slug");
//                  currentReuslt.add(currentMap);
//                }
//                System.out.println("最后结果:"+currentReuslt);
//                System.out.println("总行数:"+currentReuslt.size());
//                List<Map<String,Object>> res = getResultItem(currentReuslt,ids.substring(1,ids.length()));
//                System.out.println("返回长度:"+res.size());
//                result.addAll(res);
//                // 关闭连接
//                reader.close();
//                connection.disconnect();
//
//
//            }catch (Exception e){
//                System.out.println(e.getMessage());
//            }
//        }
//        return result;
//    }
//
//    public static List<Map<String,Object>> getResultItem(List<Map<String,Object>> oldItem,String ids){
//        try {
//            Thread.sleep(2000);
//            String getNameUrl = "https://data.mifengcha.com/api/v3/tickers?api_key=OQIYNHXPRLEA3GSP9JCVBMUHI614XOMXPJMROQGS&market=Binance&currency=USDT&size=100&slug="+ids;
//            URL url = new URL(getNameUrl);
//
//            // 创建 HTTP 连接
//            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//            connection.setRequestMethod("GET");
//
//            // 获取输入流
//            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//            // 读取 CSV 数据
//            String line1;
//            StringBuilder response  = new StringBuilder();
//            while ((line1 = reader.readLine()) != null) { // 打印每一行数据
//                response.append(line1);
//            }
//            String reponseStr = response.toString();
//            System.out.println(reponseStr);
//            JSONArray jsonArray = JSON.parseArray(reponseStr);
//            if (jsonArray != null && jsonArray.size() > 0){
//                List<Map<String,Object>> list = new ArrayList<>();
//                for(int i = 0; i < jsonArray.size();i++){
//                    JSONObject object = jsonArray.getJSONObject(i);
//                    Map<String,Object> resultItem = setKCode(object,oldItem);
//                    if (resultItem != null){
//                        list.add(resultItem);
//                    }
//                }
//                return list;
//            }
//
//        }catch (Exception e){
//            System.out.println(e.getMessage());
//        }
//        return null;
//    }
//
//
//    public static Map<String,Object> setKCode(JSONObject jsonObject,List<Map<String,Object>> list){
//        for (Map<String,Object> item : list){
//            if (item.get("code").equals(jsonObject.getString("bs"))){
//                item.put("kCode",jsonObject.get("m"));
//                return item;
//            }
//        }
//        return null;
//    }
}