yuanyou_edb.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. package services
  2. import (
  3. "eta/eta_data_analysis/models"
  4. "eta/eta_data_analysis/utils"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "strings"
  8. "time"
  9. )
  10. var YuanYouListMap = map[string]string{
  11. "国内独立炼厂产能利用率周数据统计" : "https://list.oilchem.net/5158/43854/",
  12. "国内炼厂常减压装置产能利用率月数据统计": "https://list.oilchem.net/5158/43854/",
  13. "山东独立炼厂原油到港量周数据统计": "https://list.oilchem.net/5158/43856/",
  14. "中国港口商业原油库存指数分析": "https://list.oilchem.net/5158/43857/",
  15. "山东独立炼厂原油样本库容率周数据分析": "https://list.oilchem.net/5158/43859/",
  16. "中国炼厂原油加工量月数据分析": "https://list.oilchem.net/5158/43858/",
  17. "国内原油加工量简况": "https://list.oilchem.net/5158/37164/",
  18. "国内原油产量表": "https://list.oilchem.net/5158/37164/",
  19. //"中国原油进出口量月数据统计": "https://list.oilchem.net/5158/37160/",
  20. "中国原油月度进出口数据分析报告": "https://list.oilchem.net/5158/37160/",
  21. //"美国能源信息署最新石油库存报告": "https://list.oilchem.net/5158/37147/",
  22. "美国API库存数据": "https://list.oilchem.net/5158/37147/",
  23. "国际主要汇率收盘": "https://list.oilchem.net/5158/37156/",
  24. }
  25. func YuanYouList(num int) (err error) {
  26. for k, v := range YuanYouListMap {
  27. for i := 1; i < num; i++ {
  28. listUrl := v + fmt.Sprintf("%d.html", i)
  29. fmt.Println("listUrl:", listUrl)
  30. htm, e := FetchPageHtml(listUrl)
  31. if e != nil {
  32. err = e
  33. utils.FileLog.Error(fmt.Sprintf("FetchPageHtml err:%v", err))
  34. fmt.Println("FetchPageHtml err", err)
  35. return
  36. }
  37. err = AnalysisOilchemList(htm, k)
  38. if err != nil {
  39. utils.FileLog.Error(fmt.Sprintf("AnalysisOilchemList err:%v", err))
  40. fmt.Println("AnalysisOilchemList err", err)
  41. return
  42. }
  43. time.Sleep(2 * time.Second)
  44. }
  45. }
  46. return
  47. }
  48. // 国内独立炼厂产能利用率周数据
  49. func AnalysisOilchemYuanYou1(htm []byte) (err error) {
  50. if len(htm) == 0 {
  51. utils.FileLog.Info("htm empty")
  52. return
  53. }
  54. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  55. if e != nil {
  56. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  57. return
  58. }
  59. titleList := make([]string, 0)
  60. unitList := make([]string, 0)
  61. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  62. ptext := selection.Text()
  63. if strings.Contains(ptext, "单位:") {
  64. unit := strings.Replace(ptext, "单位:", "", -1)
  65. //fmt.Println("unit:",unit)
  66. unitList = append(unitList, unit)
  67. }
  68. if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  69. title := ptext
  70. //fmt.Println("title:",title)
  71. titleList = append(titleList, title)
  72. }
  73. })
  74. area := ""
  75. title := doc.Find("h2").Text()
  76. fmt.Println("title:", title)
  77. createTimeStr := doc.Find("h2").Next().Text()
  78. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  79. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  80. createTimeStr = createTimeStr[:createTimeStrIndex]
  81. createTimeStr = strings.TrimSpace(createTimeStr)
  82. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  83. if err != nil {
  84. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  85. return
  86. }
  87. //fmt.Println("createTime:",createTime)
  88. dataTime := createTime.Format(utils.FormatDate)
  89. //fmt.Println("dataTime:",dataTime)
  90. indexList := make([]*models.BaseFromOilchemIndex, 0)
  91. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  92. table.Find("tr").First().Each(func(ii int, table2 *goquery.Selection) {
  93. table.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  94. text3 := table3.Text()
  95. text3 = strings.Replace(text3, "\n", "", -1)
  96. text3 = strings.Replace(text3, " ", "", -1)
  97. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  98. return
  99. }
  100. //fmt.Println("table3:",text3)
  101. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  102. //fmt.Println("ii:",ii)
  103. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  104. //fmt.Println("jj:",jj)
  105. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  106. //fmt.Println("tableIndex:",tableIndex)
  107. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  108. if utils.ContainsChinese(text3) && text3 != "本周" {
  109. area = text3
  110. return
  111. }
  112. if area == "" {
  113. return
  114. }
  115. value := text3
  116. value = strings.TrimRight(value, "%")
  117. //valueF, e := strconv.ParseFloat(value, 64)
  118. //if e != nil {
  119. // err = e
  120. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  121. // return
  122. //}
  123. indexName := "中国炼厂常减压装置产能利用率"
  124. fmt.Println("indexName:", indexName)
  125. fmt.Println("valueF:", value)
  126. unit := ""
  127. if strings.Contains(area, "产量") {
  128. unit = "万吨"
  129. } else {
  130. unit = "%"
  131. }
  132. item := &models.BaseFromOilchemIndex{
  133. IndexName: indexName,
  134. ClassifyId: 5,
  135. Unit: unit,
  136. Frequency: "周度",
  137. Describe: "",
  138. DataTime: dataTime,
  139. Value: value,
  140. Sort: 0,
  141. CreateTime: time.Now(),
  142. ModifyTime: time.Now(),
  143. IndexNameStr: "中国炼厂常减压装置产能利用率",
  144. MarketName: "",
  145. }
  146. indexList = append(indexList, item)
  147. area = ""
  148. })
  149. })
  150. })
  151. // 写入数据库
  152. err = PostHandleOilchem(indexList)
  153. if err != nil {
  154. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  155. fmt.Println("PostHandleOilchem err", err)
  156. return
  157. }
  158. return
  159. }
  160. // 国内炼厂常减压装置产能利用率月数据统计
  161. func AnalysisOilchemYuanYou2(htm []byte) (err error) {
  162. if len(htm) == 0 {
  163. utils.FileLog.Info("htm empty")
  164. return
  165. }
  166. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  167. if e != nil {
  168. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  169. return
  170. }
  171. titleList := make([]string, 0)
  172. unitList := make([]string, 0)
  173. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  174. ptext := selection.Text()
  175. if strings.Contains(ptext, "单位:") {
  176. unit := strings.Replace(ptext, "单位:", "", -1)
  177. //fmt.Println("unit:",unit)
  178. unitList = append(unitList, unit)
  179. }
  180. if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  181. title := ptext
  182. //fmt.Println("title:",title)
  183. titleList = append(titleList, title)
  184. }
  185. })
  186. area := ""
  187. title := doc.Find("h2").Text()
  188. fmt.Println("title:", title)
  189. createTimeStr := doc.Find("h2").Next().Text()
  190. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  191. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  192. createTimeStr = createTimeStr[:createTimeStrIndex]
  193. createTimeStr = strings.TrimSpace(createTimeStr)
  194. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  195. if err != nil {
  196. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  197. return
  198. }
  199. //fmt.Println("createTime:",createTime)
  200. dataTime := createTime.Format(utils.FormatDate)
  201. //fmt.Println("dataTime:",dataTime)
  202. indexList := make([]*models.BaseFromOilchemIndex, 0)
  203. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  204. table.Find("tr").First().Each(func(ii int, table2 *goquery.Selection) {
  205. table.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  206. text3 := table3.Text()
  207. text3 = strings.Replace(text3, "\n", "", -1)
  208. text3 = strings.Replace(text3, " ", "", -1)
  209. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  210. return
  211. }
  212. //fmt.Println("table3:",text3)
  213. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  214. //fmt.Println("ii:",ii)
  215. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  216. //fmt.Println("jj:",jj)
  217. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  218. //fmt.Println("tableIndex:",tableIndex)
  219. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  220. if utils.ContainsChinese(text3) && text3 != "本周" {
  221. area = text3
  222. return
  223. }
  224. if area == "" {
  225. return
  226. }
  227. value := text3
  228. value = strings.TrimRight(value, "%")
  229. //valueF, e := strconv.ParseFloat(value, 64)
  230. //if e != nil {
  231. // err = e
  232. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  233. // return
  234. //}
  235. indexName := "中国炼厂常减压装置产能利用率" + "(" + area + ")"
  236. fmt.Println("indexName:", indexName)
  237. fmt.Println("valueF:", value)
  238. unit := ""
  239. if strings.Contains(area, "产量") {
  240. unit = "万吨"
  241. } else {
  242. unit = "%"
  243. }
  244. item := &models.BaseFromOilchemIndex{
  245. IndexName: indexName,
  246. ClassifyId: 5,
  247. Unit: unit,
  248. Frequency: "周度",
  249. Describe: "",
  250. DataTime: dataTime,
  251. Value: value,
  252. Sort: 0,
  253. CreateTime: time.Now(),
  254. ModifyTime: time.Now(),
  255. IndexNameStr: "中国炼厂常减压装置产能利用率",
  256. MarketName: area,
  257. }
  258. indexList = append(indexList, item)
  259. area = ""
  260. })
  261. })
  262. })
  263. // 写入数据库
  264. err = PostHandleOilchem(indexList)
  265. if err != nil {
  266. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  267. fmt.Println("PostHandleOilchem err", err)
  268. return
  269. }
  270. return
  271. }
  272. // 山东独立炼厂原油到港量周数据统计
  273. func AnalysisOilchemYuanYou3(htm []byte) (err error) {
  274. if len(htm) == 0 {
  275. utils.FileLog.Info("htm empty")
  276. return
  277. }
  278. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  279. if e != nil {
  280. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  281. return
  282. }
  283. //titleList := make([]string, 0)
  284. unitList := make([]string, 0)
  285. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  286. ptext := selection.Text()
  287. if strings.Contains(ptext, "单位:") {
  288. unit := strings.Replace(ptext, "单位:", "", -1)
  289. //fmt.Println("unit:",unit)
  290. unitList = append(unitList, unit)
  291. }
  292. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  293. // title := ptext
  294. // //fmt.Println("title:",title)
  295. // titleList = append(titleList, title)
  296. //}
  297. })
  298. area := ""
  299. title := doc.Find("h2").Text()
  300. fmt.Println("title:", title)
  301. createTimeStr := doc.Find("h2").Next().Text()
  302. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  303. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  304. createTimeStr = createTimeStr[:createTimeStrIndex]
  305. createTimeStr = strings.TrimSpace(createTimeStr)
  306. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  307. if err != nil {
  308. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  309. return
  310. }
  311. //fmt.Println("createTime:",createTime)
  312. dataTime := createTime.Format(utils.FormatDate)
  313. //fmt.Println("dataTime:",dataTime)
  314. indexList := make([]*models.BaseFromOilchemIndex, 0)
  315. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  316. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  317. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  318. text3 := table3.Text()
  319. text3 = strings.Replace(text3, "\n", "", -1)
  320. text3 = strings.Replace(text3, " ", "", -1)
  321. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  322. return
  323. }
  324. //fmt.Println("table3:",text3)
  325. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  326. //fmt.Println("ii:",ii)
  327. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  328. //fmt.Println("jj:",jj)
  329. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  330. //fmt.Println("tableIndex:",tableIndex)
  331. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  332. if utils.ContainsChinese(text3) && text3 != "本周" {
  333. area = text3
  334. return
  335. }
  336. if area == "" {
  337. return
  338. }
  339. value := text3
  340. value = strings.TrimRight(value, "%")
  341. //valueF, e := strconv.ParseFloat(value, 64)
  342. //if e != nil {
  343. // err = e
  344. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  345. // return
  346. //}
  347. indexName := "山东独立炼厂原油到港量"
  348. fmt.Println("indexName:", indexName)
  349. fmt.Println("valueF:", value)
  350. //unit := ""
  351. //if strings.Contains(area, "产量") {
  352. // unit = "万吨"
  353. //} else {
  354. // unit = "%"
  355. //}
  356. item := &models.BaseFromOilchemIndex{
  357. IndexName: indexName,
  358. ClassifyId: 5,
  359. Unit: "万吨",
  360. Frequency: "周度",
  361. Describe: "",
  362. DataTime: dataTime,
  363. Value: value,
  364. Sort: 0,
  365. CreateTime: time.Now(),
  366. ModifyTime: time.Now(),
  367. IndexNameStr: indexName,
  368. MarketName: "",
  369. }
  370. indexList = append(indexList, item)
  371. area = ""
  372. })
  373. })
  374. })
  375. // 写入数据库
  376. err = PostHandleOilchem(indexList)
  377. if err != nil {
  378. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  379. fmt.Println("PostHandleOilchem err", err)
  380. return
  381. }
  382. return
  383. }
  384. // 中国港口商业原油库存指数分析
  385. func AnalysisOilchemYuanYou4(htm []byte) (err error) {
  386. if len(htm) == 0 {
  387. utils.FileLog.Info("htm empty")
  388. return
  389. }
  390. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  391. if e != nil {
  392. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  393. return
  394. }
  395. //titleList := make([]string, 0)
  396. unitList := make([]string, 0)
  397. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  398. ptext := selection.Text()
  399. if strings.Contains(ptext, "单位:") {
  400. unit := strings.Replace(ptext, "单位:", "", -1)
  401. //fmt.Println("unit:",unit)
  402. unitList = append(unitList, unit)
  403. }
  404. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  405. // title := ptext
  406. // //fmt.Println("title:",title)
  407. // titleList = append(titleList, title)
  408. //}
  409. })
  410. area := ""
  411. title := doc.Find("h2").Text()
  412. fmt.Println("title:", title)
  413. createTimeStr := doc.Find("h2").Next().Text()
  414. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  415. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  416. createTimeStr = createTimeStr[:createTimeStrIndex]
  417. createTimeStr = strings.TrimSpace(createTimeStr)
  418. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  419. if err != nil {
  420. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  421. return
  422. }
  423. //fmt.Println("createTime:",createTime)
  424. dataTime := createTime.Format(utils.FormatDate)
  425. //fmt.Println("dataTime:",dataTime)
  426. indexList := make([]*models.BaseFromOilchemIndex, 0)
  427. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  428. table.Find("tr").First().Each(func(ii int, table2 *goquery.Selection) {
  429. table.Find("p").Each(func(jj int, table3 *goquery.Selection) {
  430. text3 := table3.Text()
  431. text3 = strings.Replace(text3, "\n", "", -1)
  432. text3 = strings.Replace(text3, " ", "", -1)
  433. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  434. return
  435. }
  436. //fmt.Println("table3:",text3)
  437. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  438. //fmt.Println("ii:",ii)
  439. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  440. //fmt.Println("jj:",jj)
  441. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  442. //fmt.Println("tableIndex:",tableIndex)
  443. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  444. if utils.ContainsChinese(text3) && text3 != "本周"{
  445. area = text3
  446. return
  447. }
  448. if area == "" {
  449. return
  450. }
  451. value := text3
  452. value = strings.TrimRight(value, "%")
  453. //valueF, e := strconv.ParseFloat(value, 64)
  454. //if e != nil {
  455. // err = e
  456. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  457. // return
  458. //}
  459. indexName := "中国港口商业原油样本库存指数" + "(" + area + ")"
  460. fmt.Println("indexName:", indexName)
  461. fmt.Println("valueF:", value)
  462. //unit := ""
  463. //if strings.Contains(area, "产量") {
  464. // unit = "万吨"
  465. //} else {
  466. // unit = "%"
  467. //}
  468. item := &models.BaseFromOilchemIndex{
  469. IndexName: indexName,
  470. ClassifyId: 5,
  471. Unit: "%",
  472. Frequency: "周度",
  473. Describe: "",
  474. DataTime: dataTime,
  475. Value: value,
  476. Sort: 0,
  477. CreateTime: time.Now(),
  478. ModifyTime: time.Now(),
  479. IndexNameStr: "中国港口商业原油样本库存指数",
  480. MarketName: area,
  481. }
  482. indexList = append(indexList, item)
  483. area = ""
  484. })
  485. })
  486. })
  487. // 写入数据库
  488. err = PostHandleOilchem(indexList)
  489. if err != nil {
  490. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  491. fmt.Println("PostHandleOilchem err", err)
  492. return
  493. }
  494. return
  495. }
  496. // 山东独立炼厂原油样本库容率周数据分析
  497. func AnalysisOilchemYuanYou5(htm []byte) (err error) {
  498. if len(htm) == 0 {
  499. utils.FileLog.Info("htm empty")
  500. return
  501. }
  502. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  503. if e != nil {
  504. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  505. return
  506. }
  507. //titleList := make([]string, 0)
  508. unitList := make([]string, 0)
  509. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  510. ptext := selection.Text()
  511. if strings.Contains(ptext, "单位:") {
  512. unit := strings.Replace(ptext, "单位:", "", -1)
  513. //fmt.Println("unit:",unit)
  514. unitList = append(unitList, unit)
  515. }
  516. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  517. // title := ptext
  518. // //fmt.Println("title:",title)
  519. // titleList = append(titleList, title)
  520. //}
  521. })
  522. area := ""
  523. title := doc.Find("h2").Text()
  524. fmt.Println("title:", title)
  525. createTimeStr := doc.Find("h2").Next().Text()
  526. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  527. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  528. createTimeStr = createTimeStr[:createTimeStrIndex]
  529. createTimeStr = strings.TrimSpace(createTimeStr)
  530. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  531. if err != nil {
  532. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  533. return
  534. }
  535. //fmt.Println("createTime:",createTime)
  536. dataTime := createTime.Format(utils.FormatDate)
  537. //fmt.Println("dataTime:",dataTime)
  538. indexList := make([]*models.BaseFromOilchemIndex, 0)
  539. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  540. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  541. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  542. text3 := table3.Text()
  543. text3 = strings.Replace(text3, "\n", "", -1)
  544. text3 = strings.Replace(text3, " ", "", -1)
  545. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  546. return
  547. }
  548. //fmt.Println("table3:",text3)
  549. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  550. //fmt.Println("ii:",ii)
  551. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  552. //fmt.Println("jj:",jj)
  553. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  554. //fmt.Println("tableIndex:",tableIndex)
  555. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  556. if utils.ContainsChinese(text3) && text3 != "本周" {
  557. area = text3
  558. return
  559. }
  560. if area == "" {
  561. return
  562. }
  563. value := text3
  564. value = strings.TrimRight(value, "%")
  565. //valueF, e := strconv.ParseFloat(value, 64)
  566. //if e != nil {
  567. // err = e
  568. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  569. // return
  570. //}
  571. indexName := "山东独立炼厂原油样本库容率"
  572. fmt.Println("indexName:", indexName)
  573. fmt.Println("valueF:", value)
  574. //unit := ""
  575. //if strings.Contains(area, "产量") {
  576. // unit = "万吨"
  577. //} else {
  578. // unit = "%"
  579. //}
  580. item := &models.BaseFromOilchemIndex{
  581. IndexName: indexName,
  582. ClassifyId: 5,
  583. Unit: "%",
  584. Frequency: "周度",
  585. Describe: "",
  586. DataTime: dataTime,
  587. Value: value,
  588. Sort: 0,
  589. CreateTime: time.Now(),
  590. ModifyTime: time.Now(),
  591. IndexNameStr: indexName,
  592. MarketName: "",
  593. }
  594. indexList = append(indexList, item)
  595. area = ""
  596. })
  597. })
  598. })
  599. // 写入数据库
  600. err = PostHandleOilchem(indexList)
  601. if err != nil {
  602. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  603. fmt.Println("PostHandleOilchem err", err)
  604. return
  605. }
  606. return
  607. }
  608. // 中国炼厂原油加工量月数据分析
  609. func AnalysisOilchemYuanYou6(htm []byte) (err error) {
  610. if len(htm) == 0 {
  611. utils.FileLog.Info("htm empty")
  612. return
  613. }
  614. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  615. if e != nil {
  616. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  617. return
  618. }
  619. //titleList := make([]string, 0)
  620. unitList := make([]string, 0)
  621. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  622. ptext := selection.Text()
  623. if strings.Contains(ptext, "单位:") {
  624. unit := strings.Replace(ptext, "单位:", "", -1)
  625. //fmt.Println("unit:",unit)
  626. unitList = append(unitList, unit)
  627. }
  628. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  629. // title := ptext
  630. // //fmt.Println("title:",title)
  631. // titleList = append(titleList, title)
  632. //}
  633. })
  634. area := ""
  635. title := doc.Find("h2").Text()
  636. fmt.Println("title:", title)
  637. createTimeStr := doc.Find("h2").Next().Text()
  638. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  639. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  640. createTimeStr = createTimeStr[:createTimeStrIndex]
  641. createTimeStr = strings.TrimSpace(createTimeStr)
  642. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  643. if err != nil {
  644. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  645. return
  646. }
  647. //fmt.Println("createTime:",createTime)
  648. dataTime := createTime.Format(utils.FormatDate)
  649. //fmt.Println("dataTime:",dataTime)
  650. indexList := make([]*models.BaseFromOilchemIndex, 0)
  651. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  652. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  653. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  654. text3 := table3.Text()
  655. text3 = strings.Replace(text3, "\n", "", -1)
  656. text3 = strings.Replace(text3, " ", "", -1)
  657. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  658. return
  659. }
  660. //fmt.Println("table3:",text3)
  661. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  662. //fmt.Println("ii:",ii)
  663. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  664. //fmt.Println("jj:",jj)
  665. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  666. //fmt.Println("tableIndex:",tableIndex)
  667. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  668. if utils.ContainsChinese(text3) && text3 != "本周" {
  669. area = text3
  670. return
  671. }
  672. if area == "" {
  673. return
  674. }
  675. value := text3
  676. value = strings.TrimRight(value, "%")
  677. //valueF, e := strconv.ParseFloat(value, 64)
  678. //if e != nil {
  679. // err = e
  680. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  681. // return
  682. //}
  683. indexName := "中国炼厂原油加工量"
  684. fmt.Println("indexName:", indexName)
  685. fmt.Println("valueF:", value)
  686. //unit := ""
  687. //if strings.Contains(area, "产量") {
  688. // unit = "万吨"
  689. //} else {
  690. // unit = "%"
  691. //}
  692. item := &models.BaseFromOilchemIndex{
  693. IndexName: indexName,
  694. ClassifyId: 5,
  695. Unit: "万吨",
  696. Frequency: "月度",
  697. Describe: "",
  698. DataTime: dataTime,
  699. Value: value,
  700. Sort: 0,
  701. CreateTime: time.Now(),
  702. ModifyTime: time.Now(),
  703. IndexNameStr: indexName,
  704. MarketName: "",
  705. }
  706. indexList = append(indexList, item)
  707. area = ""
  708. })
  709. })
  710. })
  711. // 写入数据库
  712. err = PostHandleOilchem(indexList)
  713. if err != nil {
  714. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  715. fmt.Println("PostHandleOilchem err", err)
  716. return
  717. }
  718. return
  719. }
  720. // 国内原油加工量简况
  721. func AnalysisOilchemYuanYou7(htm []byte) (err error) {
  722. if len(htm) == 0 {
  723. utils.FileLog.Info("htm empty")
  724. return
  725. }
  726. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  727. if e != nil {
  728. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  729. return
  730. }
  731. //titleList := make([]string, 0)
  732. unitList := make([]string, 0)
  733. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  734. ptext := selection.Text()
  735. if strings.Contains(ptext, "单位:") {
  736. unit := strings.Replace(ptext, "单位:", "", -1)
  737. //fmt.Println("unit:",unit)
  738. unitList = append(unitList, unit)
  739. }
  740. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  741. // title := ptext
  742. // //fmt.Println("title:",title)
  743. // titleList = append(titleList, title)
  744. //}
  745. })
  746. area := ""
  747. title := doc.Find("h2").Text()
  748. fmt.Println("title:", title)
  749. createTimeStr := doc.Find("h2").Next().Text()
  750. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  751. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  752. createTimeStr = createTimeStr[:createTimeStrIndex]
  753. createTimeStr = strings.TrimSpace(createTimeStr)
  754. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  755. if err != nil {
  756. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  757. return
  758. }
  759. //fmt.Println("createTime:",createTime)
  760. dataTime := createTime.Format(utils.FormatDate)
  761. //fmt.Println("dataTime:",dataTime)
  762. indexList := make([]*models.BaseFromOilchemIndex, 0)
  763. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  764. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  765. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  766. text3 := table3.Text()
  767. text3 = strings.Replace(text3, "\n", "", -1)
  768. text3 = strings.Replace(text3, " ", "", -1)
  769. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  770. return
  771. }
  772. //fmt.Println("table3:",text3)
  773. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  774. //fmt.Println("ii:",ii)
  775. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  776. //fmt.Println("jj:",jj)
  777. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  778. //fmt.Println("tableIndex:",tableIndex)
  779. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  780. if utils.ContainsChinese(text3) && text3 != "本周" {
  781. area = text3
  782. return
  783. }
  784. if area == "" {
  785. return
  786. }
  787. value := text3
  788. value = strings.TrimRight(value, "%")
  789. //valueF, e := strconv.ParseFloat(value, 64)
  790. //if e != nil {
  791. // err = e
  792. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  793. // return
  794. //}
  795. indexName := "国内原油加工量"
  796. fmt.Println("indexName:", indexName)
  797. fmt.Println("valueF:", value)
  798. //unit := ""
  799. //if strings.Contains(area, "产量") {
  800. // unit = "万吨"
  801. //} else {
  802. // unit = "%"
  803. //}
  804. item := &models.BaseFromOilchemIndex{
  805. IndexName: indexName,
  806. ClassifyId: 5,
  807. Unit: "万吨",
  808. Frequency: "月度",
  809. Describe: "",
  810. DataTime: dataTime,
  811. Value: value,
  812. Sort: 0,
  813. CreateTime: time.Now(),
  814. ModifyTime: time.Now(),
  815. IndexNameStr: indexName,
  816. MarketName: "",
  817. }
  818. indexList = append(indexList, item)
  819. area = ""
  820. })
  821. })
  822. })
  823. // 写入数据库
  824. err = PostHandleOilchem(indexList)
  825. if err != nil {
  826. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  827. fmt.Println("PostHandleOilchem err", err)
  828. return
  829. }
  830. return
  831. }
  832. // 国内原油加工量简况
  833. func AnalysisOilchemYuanYou8(htm []byte) (err error) {
  834. if len(htm) == 0 {
  835. utils.FileLog.Info("htm empty")
  836. return
  837. }
  838. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  839. if e != nil {
  840. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  841. return
  842. }
  843. //titleList := make([]string, 0)
  844. unitList := make([]string, 0)
  845. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  846. ptext := selection.Text()
  847. if strings.Contains(ptext, "单位:") {
  848. unit := strings.Replace(ptext, "单位:", "", -1)
  849. //fmt.Println("unit:",unit)
  850. unitList = append(unitList, unit)
  851. }
  852. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  853. // title := ptext
  854. // //fmt.Println("title:",title)
  855. // titleList = append(titleList, title)
  856. //}
  857. })
  858. area := ""
  859. title := doc.Find("h2").Text()
  860. fmt.Println("title:", title)
  861. createTimeStr := doc.Find("h2").Next().Text()
  862. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  863. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  864. createTimeStr = createTimeStr[:createTimeStrIndex]
  865. createTimeStr = strings.TrimSpace(createTimeStr)
  866. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  867. if err != nil {
  868. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  869. return
  870. }
  871. //fmt.Println("createTime:",createTime)
  872. dataTime := createTime.Format(utils.FormatDate)
  873. //fmt.Println("dataTime:",dataTime)
  874. indexList := make([]*models.BaseFromOilchemIndex, 0)
  875. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  876. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  877. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  878. text3 := table3.Text()
  879. text3 = strings.Replace(text3, "\n", "", -1)
  880. text3 = strings.Replace(text3, " ", "", -1)
  881. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  882. return
  883. }
  884. //fmt.Println("table3:",text3)
  885. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  886. //fmt.Println("ii:",ii)
  887. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  888. //fmt.Println("jj:",jj)
  889. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  890. //fmt.Println("tableIndex:",tableIndex)
  891. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  892. if utils.ContainsChinese(text3) && text3 != "本周" {
  893. area = text3
  894. return
  895. }
  896. if area == "" {
  897. return
  898. }
  899. value := text3
  900. value = strings.TrimRight(value, "%")
  901. //valueF, e := strconv.ParseFloat(value, 64)
  902. //if e != nil {
  903. // err = e
  904. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  905. // return
  906. //}
  907. indexName := "国内原油产量表"
  908. fmt.Println("indexName:", indexName)
  909. fmt.Println("valueF:", value)
  910. //unit := ""
  911. //if strings.Contains(area, "产量") {
  912. // unit = "万吨"
  913. //} else {
  914. // unit = "%"
  915. //}
  916. item := &models.BaseFromOilchemIndex{
  917. IndexName: indexName,
  918. ClassifyId: 5,
  919. Unit: "万吨",
  920. Frequency: "月度",
  921. Describe: "",
  922. DataTime: dataTime,
  923. Value: value,
  924. Sort: 0,
  925. CreateTime: time.Now(),
  926. ModifyTime: time.Now(),
  927. IndexNameStr: indexName,
  928. MarketName: "",
  929. }
  930. indexList = append(indexList, item)
  931. area = ""
  932. })
  933. })
  934. })
  935. // 写入数据库
  936. err = PostHandleOilchem(indexList)
  937. if err != nil {
  938. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  939. fmt.Println("PostHandleOilchem err", err)
  940. return
  941. }
  942. return
  943. }
  944. // 中国原油进出口量月数据统计 todo
  945. func AnalysisOilchemYuanYou9(htm []byte) (err error) {
  946. if len(htm) == 0 {
  947. utils.FileLog.Info("htm empty")
  948. return
  949. }
  950. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  951. if e != nil {
  952. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  953. return
  954. }
  955. //titleList := make([]string, 0)
  956. unitList := make([]string, 0)
  957. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  958. ptext := selection.Text()
  959. if strings.Contains(ptext, "单位:") {
  960. unit := strings.Replace(ptext, "单位:", "", -1)
  961. //fmt.Println("unit:",unit)
  962. unitList = append(unitList, unit)
  963. }
  964. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  965. // title := ptext
  966. // //fmt.Println("title:",title)
  967. // titleList = append(titleList, title)
  968. //}
  969. })
  970. area := ""
  971. title := doc.Find("h2").Text()
  972. fmt.Println("title:", title)
  973. createTimeStr := doc.Find("h2").Next().Text()
  974. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  975. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  976. createTimeStr = createTimeStr[:createTimeStrIndex]
  977. createTimeStr = strings.TrimSpace(createTimeStr)
  978. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  979. if err != nil {
  980. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  981. return
  982. }
  983. //fmt.Println("createTime:",createTime)
  984. dataTime := createTime.Format(utils.FormatDate)
  985. //fmt.Println("dataTime:",dataTime)
  986. indexList := make([]*models.BaseFromOilchemIndex, 0)
  987. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  988. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  989. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  990. text3 := table3.Text()
  991. text3 = strings.Replace(text3, "\n", "", -1)
  992. text3 = strings.Replace(text3, " ", "", -1)
  993. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  994. return
  995. }
  996. //fmt.Println("table3:",text3)
  997. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  998. //fmt.Println("ii:",ii)
  999. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  1000. //fmt.Println("jj:",jj)
  1001. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  1002. //fmt.Println("tableIndex:",tableIndex)
  1003. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  1004. if utils.ContainsChinese(text3) && text3 != "本周" {
  1005. area = text3
  1006. return
  1007. }
  1008. if area == "" {
  1009. return
  1010. }
  1011. value := text3
  1012. value = strings.TrimRight(value, "%")
  1013. //valueF, e := strconv.ParseFloat(value, 64)
  1014. //if e != nil {
  1015. // err = e
  1016. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  1017. // return
  1018. //}
  1019. indexName := "国内原油产量表"
  1020. fmt.Println("indexName:", indexName)
  1021. fmt.Println("valueF:", value)
  1022. //unit := ""
  1023. //if strings.Contains(area, "产量") {
  1024. // unit = "万吨"
  1025. //} else {
  1026. // unit = "%"
  1027. //}
  1028. item := &models.BaseFromOilchemIndex{
  1029. IndexName: indexName,
  1030. ClassifyId: 5,
  1031. Unit: "万吨",
  1032. Frequency: "月度",
  1033. Describe: "",
  1034. DataTime: dataTime,
  1035. Value: value,
  1036. Sort: 0,
  1037. CreateTime: time.Now(),
  1038. ModifyTime: time.Now(),
  1039. IndexNameStr: indexName,
  1040. MarketName: "",
  1041. }
  1042. indexList = append(indexList, item)
  1043. area = ""
  1044. })
  1045. })
  1046. })
  1047. // 写入数据库
  1048. err = PostHandleOilchem(indexList)
  1049. if err != nil {
  1050. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  1051. fmt.Println("PostHandleOilchem err", err)
  1052. return
  1053. }
  1054. return
  1055. }
  1056. // 中国原油月度进出口数据分析报告
  1057. func AnalysisOilchemYuanYou10(htm []byte) (err error) {
  1058. if len(htm) == 0 {
  1059. utils.FileLog.Info("htm empty")
  1060. return
  1061. }
  1062. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  1063. if e != nil {
  1064. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  1065. return
  1066. }
  1067. //titleList := make([]string, 0)
  1068. unitList := make([]string, 0)
  1069. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  1070. ptext := selection.Text()
  1071. if strings.Contains(ptext, "单位:") {
  1072. unit := strings.Replace(ptext, "单位:", "", -1)
  1073. //fmt.Println("unit:",unit)
  1074. unitList = append(unitList, unit)
  1075. }
  1076. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  1077. // title := ptext
  1078. // //fmt.Println("title:",title)
  1079. // titleList = append(titleList, title)
  1080. //}
  1081. })
  1082. area := ""
  1083. title := doc.Find("h2").Text()
  1084. fmt.Println("title:", title)
  1085. createTimeStr := doc.Find("h2").Next().Text()
  1086. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  1087. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  1088. createTimeStr = createTimeStr[:createTimeStrIndex]
  1089. createTimeStr = strings.TrimSpace(createTimeStr)
  1090. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  1091. if err != nil {
  1092. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  1093. return
  1094. }
  1095. //fmt.Println("createTime:",createTime)
  1096. dataTime := createTime.Format(utils.FormatDate)
  1097. //fmt.Println("dataTime:",dataTime)
  1098. indexList := make([]*models.BaseFromOilchemIndex, 0)
  1099. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  1100. if tableIndex != 1 {
  1101. return
  1102. }
  1103. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  1104. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  1105. text3 := table3.Text()
  1106. text3 = strings.Replace(text3, "\n", "", -1)
  1107. text3 = strings.Replace(text3, " ", "", -1)
  1108. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  1109. return
  1110. }
  1111. //fmt.Println("table3:",text3)
  1112. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  1113. //fmt.Println("ii:",ii)
  1114. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  1115. //fmt.Println("jj:",jj)
  1116. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  1117. //fmt.Println("tableIndex:",tableIndex)
  1118. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  1119. if utils.ContainsChinese(text3) && text3 != "本周" {
  1120. area = text3
  1121. return
  1122. }
  1123. if area == "" {
  1124. return
  1125. }
  1126. value := text3
  1127. value = strings.TrimRight(value, "%")
  1128. //valueF, e := strconv.ParseFloat(value, 64)
  1129. //if e != nil {
  1130. // err = e
  1131. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  1132. // return
  1133. //}
  1134. indexName := "中国原油按贸易方式进口量"+"(" + area +")"
  1135. fmt.Println("indexName:", indexName)
  1136. fmt.Println("valueF:", value)
  1137. //unit := ""
  1138. //if strings.Contains(area, "产量") {
  1139. // unit = "万吨"
  1140. //} else {
  1141. // unit = "%"
  1142. //}
  1143. item := &models.BaseFromOilchemIndex{
  1144. IndexName: indexName,
  1145. ClassifyId: 5,
  1146. Unit: "万吨",
  1147. Frequency: "月度",
  1148. Describe: "",
  1149. DataTime: dataTime,
  1150. Value: value,
  1151. Sort: 0,
  1152. CreateTime: time.Now(),
  1153. ModifyTime: time.Now(),
  1154. IndexNameStr: indexName,
  1155. MarketName: area,
  1156. }
  1157. indexList = append(indexList, item)
  1158. area = ""
  1159. })
  1160. })
  1161. })
  1162. // 写入数据库
  1163. err = PostHandleOilchem(indexList)
  1164. if err != nil {
  1165. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  1166. fmt.Println("PostHandleOilchem err", err)
  1167. return
  1168. }
  1169. return
  1170. }
  1171. // 美国能源信息署最新石油库存报告 todo
  1172. func AnalysisOilchemYuanYou11(htm []byte) (err error) {
  1173. if len(htm) == 0 {
  1174. utils.FileLog.Info("htm empty")
  1175. return
  1176. }
  1177. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  1178. if e != nil {
  1179. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  1180. return
  1181. }
  1182. //titleList := make([]string, 0)
  1183. unitList := make([]string, 0)
  1184. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  1185. ptext := selection.Text()
  1186. if strings.Contains(ptext, "单位:") {
  1187. unit := strings.Replace(ptext, "单位:", "", -1)
  1188. //fmt.Println("unit:",unit)
  1189. unitList = append(unitList, unit)
  1190. }
  1191. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  1192. // title := ptext
  1193. // //fmt.Println("title:",title)
  1194. // titleList = append(titleList, title)
  1195. //}
  1196. })
  1197. area := ""
  1198. title := doc.Find("h2").Text()
  1199. fmt.Println("title:", title)
  1200. createTimeStr := doc.Find("h2").Next().Text()
  1201. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  1202. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  1203. createTimeStr = createTimeStr[:createTimeStrIndex]
  1204. createTimeStr = strings.TrimSpace(createTimeStr)
  1205. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  1206. if err != nil {
  1207. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  1208. return
  1209. }
  1210. //fmt.Println("createTime:",createTime)
  1211. dataTime := createTime.Format(utils.FormatDate)
  1212. //fmt.Println("dataTime:",dataTime)
  1213. indexList := make([]*models.BaseFromOilchemIndex, 0)
  1214. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  1215. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  1216. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  1217. text3 := table3.Text()
  1218. text3 = strings.Replace(text3, "\n", "", -1)
  1219. text3 = strings.Replace(text3, " ", "", -1)
  1220. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  1221. return
  1222. }
  1223. //fmt.Println("table3:",text3)
  1224. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  1225. //fmt.Println("ii:",ii)
  1226. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  1227. //fmt.Println("jj:",jj)
  1228. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  1229. //fmt.Println("tableIndex:",tableIndex)
  1230. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  1231. if utils.ContainsChinese(text3) && text3 != "本周" {
  1232. area = text3
  1233. return
  1234. }
  1235. if area == "" {
  1236. return
  1237. }
  1238. value := text3
  1239. value = strings.TrimRight(value, "%")
  1240. //valueF, e := strconv.ParseFloat(value, 64)
  1241. //if e != nil {
  1242. // err = e
  1243. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  1244. // return
  1245. //}
  1246. indexName := "中国原油按贸易方式进口量"+"(" + area +")"
  1247. fmt.Println("indexName:", indexName)
  1248. fmt.Println("valueF:", value)
  1249. //unit := ""
  1250. //if strings.Contains(area, "产量") {
  1251. // unit = "万吨"
  1252. //} else {
  1253. // unit = "%"
  1254. //}
  1255. item := &models.BaseFromOilchemIndex{
  1256. IndexName: indexName,
  1257. ClassifyId: 5,
  1258. Unit: "万吨",
  1259. Frequency: "月度",
  1260. Describe: "",
  1261. DataTime: dataTime,
  1262. Value: value,
  1263. Sort: 0,
  1264. CreateTime: time.Now(),
  1265. ModifyTime: time.Now(),
  1266. IndexNameStr: indexName,
  1267. MarketName: area,
  1268. }
  1269. indexList = append(indexList, item)
  1270. area = ""
  1271. })
  1272. })
  1273. })
  1274. // 写入数据库
  1275. err = PostHandleOilchem(indexList)
  1276. if err != nil {
  1277. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  1278. fmt.Println("PostHandleOilchem err", err)
  1279. return
  1280. }
  1281. return
  1282. }
  1283. // 美国API库存数据
  1284. func AnalysisOilchemYuanYou12(htm []byte) (err error) {
  1285. if len(htm) == 0 {
  1286. utils.FileLog.Info("htm empty")
  1287. return
  1288. }
  1289. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  1290. if e != nil {
  1291. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  1292. return
  1293. }
  1294. //titleList := make([]string, 0)
  1295. unitList := make([]string, 0)
  1296. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  1297. ptext := selection.Text()
  1298. if strings.Contains(ptext, "单位:") {
  1299. unit := strings.Replace(ptext, "单位:", "", -1)
  1300. //fmt.Println("unit:",unit)
  1301. unitList = append(unitList, unit)
  1302. }
  1303. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  1304. // title := ptext
  1305. // //fmt.Println("title:",title)
  1306. // titleList = append(titleList, title)
  1307. //}
  1308. })
  1309. area := ""
  1310. title := doc.Find("h2").Text()
  1311. fmt.Println("title:", title)
  1312. createTimeStr := doc.Find("h2").Next().Text()
  1313. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  1314. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  1315. createTimeStr = createTimeStr[:createTimeStrIndex]
  1316. createTimeStr = strings.TrimSpace(createTimeStr)
  1317. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  1318. if err != nil {
  1319. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  1320. return
  1321. }
  1322. //fmt.Println("createTime:",createTime)
  1323. dataTime := createTime.Format(utils.FormatDate)
  1324. //fmt.Println("dataTime:",dataTime)
  1325. indexList := make([]*models.BaseFromOilchemIndex, 0)
  1326. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  1327. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  1328. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  1329. text3 := table3.Text()
  1330. text3 = strings.Replace(text3, "\n", "", -1)
  1331. text3 = strings.Replace(text3, " ", "", -1)
  1332. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  1333. return
  1334. }
  1335. //fmt.Println("table3:",text3)
  1336. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  1337. //fmt.Println("ii:",ii)
  1338. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  1339. //fmt.Println("jj:",jj)
  1340. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  1341. //fmt.Println("tableIndex:",tableIndex)
  1342. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  1343. if utils.ContainsChinese(text3) && text3 != "本周" {
  1344. area = text3
  1345. return
  1346. }
  1347. if area == "" {
  1348. return
  1349. }
  1350. value := text3
  1351. value = strings.TrimRight(value, "%")
  1352. //valueF, e := strconv.ParseFloat(value, 64)
  1353. //if e != nil {
  1354. // err = e
  1355. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  1356. // return
  1357. //}
  1358. if area == "与上周增长比" {
  1359. area = ""
  1360. return
  1361. }
  1362. indexName := "美国API原油库存数据"
  1363. fmt.Println("indexName:", indexName)
  1364. fmt.Println("valueF:", value)
  1365. //unit := ""
  1366. //if strings.Contains(area, "产量") {
  1367. // unit = "万吨"
  1368. //} else {
  1369. // unit = "%"
  1370. //}
  1371. item := &models.BaseFromOilchemIndex{
  1372. IndexName: indexName,
  1373. ClassifyId: 5,
  1374. Unit: "亿桶",
  1375. Frequency: "月度",
  1376. Describe: "",
  1377. DataTime: dataTime,
  1378. Value: value,
  1379. Sort: 0,
  1380. CreateTime: time.Now(),
  1381. ModifyTime: time.Now(),
  1382. IndexNameStr: indexName,
  1383. MarketName: "",
  1384. }
  1385. indexList = append(indexList, item)
  1386. area = ""
  1387. })
  1388. })
  1389. })
  1390. // 写入数据库
  1391. err = PostHandleOilchem(indexList)
  1392. if err != nil {
  1393. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  1394. fmt.Println("PostHandleOilchem err", err)
  1395. return
  1396. }
  1397. return
  1398. }
  1399. // 国际主要汇率收盘
  1400. func AnalysisOilchemYuanYou13(htm []byte) (err error) {
  1401. if len(htm) == 0 {
  1402. utils.FileLog.Info("htm empty")
  1403. return
  1404. }
  1405. doc, e := goquery.NewDocumentFromReader(strings.NewReader(string(htm)))
  1406. if e != nil {
  1407. err = fmt.Errorf("NewDocumentFromReader err: %v", e)
  1408. return
  1409. }
  1410. //titleList := make([]string, 0)
  1411. unitList := make([]string, 0)
  1412. doc.Find("p").Each(func(i int, selection *goquery.Selection) {
  1413. ptext := selection.Text()
  1414. if strings.Contains(ptext, "单位:") {
  1415. unit := strings.Replace(ptext, "单位:", "", -1)
  1416. //fmt.Println("unit:",unit)
  1417. unitList = append(unitList, unit)
  1418. }
  1419. //if strings.Contains(ptext, "国内独立炼厂产能利用率周数据") {
  1420. // title := ptext
  1421. // //fmt.Println("title:",title)
  1422. // titleList = append(titleList, title)
  1423. //}
  1424. })
  1425. area := ""
  1426. title := doc.Find("h2").Text()
  1427. fmt.Println("title:", title)
  1428. createTimeStr := doc.Find("h2").Next().Text()
  1429. createTimeStr = strings.TrimLeft(createTimeStr, "发布时间:")
  1430. createTimeStrIndex := strings.Index(createTimeStr, "来源:")
  1431. createTimeStr = createTimeStr[:createTimeStrIndex]
  1432. createTimeStr = strings.TrimSpace(createTimeStr)
  1433. createTime, err := time.Parse(utils.HlbFormatDateTimeNoSecond, createTimeStr)
  1434. if err != nil {
  1435. utils.FileLog.Error(fmt.Sprintf("time.Parse err:%v", err))
  1436. return
  1437. }
  1438. //fmt.Println("createTime:",createTime)
  1439. dataTime := createTime.Format(utils.FormatDate)
  1440. //fmt.Println("dataTime:",dataTime)
  1441. indexList := make([]*models.BaseFromOilchemIndex, 0)
  1442. doc.Find("tbody").Each(func(tableIndex int, table *goquery.Selection) {
  1443. table.Find("tr:not(.firstRow)").Each(func(ii int, table2 *goquery.Selection) {
  1444. table2.Find("td").Each(func(jj int, table3 *goquery.Selection) {
  1445. text3 := table3.Text()
  1446. text3 = strings.Replace(text3, "\n", "", -1)
  1447. text3 = strings.Replace(text3, " ", "", -1)
  1448. if text3 == "上周" || text3 == "环比" || text3 == "地区" {
  1449. return
  1450. }
  1451. //fmt.Println("table3:",text3)
  1452. //utils.FileLog.Info(fmt.Sprintf("table3:%s",text3))
  1453. //fmt.Println("ii:",ii)
  1454. //utils.FileLog.Info(fmt.Sprintf("ii:%d",ii))
  1455. //fmt.Println("jj:",jj)
  1456. //utils.FileLog.Info(fmt.Sprintf("jj:%d",jj))
  1457. //fmt.Println("tableIndex:",tableIndex)
  1458. //utils.FileLog.Info(fmt.Sprintf("tableIndex:%d",tableIndex))
  1459. if utils.ContainsChinese(text3) && text3 != "本周" {
  1460. area = text3
  1461. return
  1462. }
  1463. if area == "" {
  1464. return
  1465. }
  1466. value := text3
  1467. value = strings.TrimRight(value, "%")
  1468. //valueF, e := strconv.ParseFloat(value, 64)
  1469. //if e != nil {
  1470. // err = e
  1471. // utils.FileLog.Error(fmt.Sprintf("strconv.ParseFloat err:%v",e))
  1472. // return
  1473. //}
  1474. indexName := "国际主要汇率收盘价" +"("+area+")"
  1475. fmt.Println("indexName:", indexName)
  1476. fmt.Println("valueF:", value)
  1477. //unit := ""
  1478. //if strings.Contains(area, "产量") {
  1479. // unit = "万吨"
  1480. //} else {
  1481. // unit = "%"
  1482. //}
  1483. item := &models.BaseFromOilchemIndex{
  1484. IndexName: indexName,
  1485. ClassifyId: 5,
  1486. Unit: "无",
  1487. Frequency: "月度",
  1488. Describe: "",
  1489. DataTime: dataTime,
  1490. Value: value,
  1491. Sort: 0,
  1492. CreateTime: time.Now(),
  1493. ModifyTime: time.Now(),
  1494. IndexNameStr: "国际主要汇率收盘价",
  1495. MarketName: area,
  1496. }
  1497. indexList = append(indexList, item)
  1498. area = ""
  1499. })
  1500. })
  1501. })
  1502. // 写入数据库
  1503. err = PostHandleOilchem(indexList)
  1504. if err != nil {
  1505. utils.FileLog.Error(fmt.Sprintf("PostHandleOilchem err:%v", err))
  1506. fmt.Println("PostHandleOilchem err", err)
  1507. return
  1508. }
  1509. return
  1510. }