Class: WordLib
- Inherits:
-
Object
- Object
- WordLib
- Defined in:
- lib/deltago.rb
Instance Method Summary collapse
- #change_url(url) ⇒ Object
-
#initialize(user_id, user_pw, url) ⇒ WordLib
constructor
A new instance of WordLib.
- #update(product, url_memory, title, text_top, text_bottom, add_text, add_text_check, category, tag_setting, search, url_change_check, proxy_check, proxy_ip) ⇒ Object
- #word_image_update(image_path, wpnonce, post_id, product_id) ⇒ Object
Constructor Details
#initialize(user_id, user_pw, url) ⇒ WordLib
Returns a new instance of WordLib.
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 |
# File 'lib/deltago.rb', line 1512 def initialize(user_id, user_pw, url) @url = url @form2 = {'log' => user_id, 'pwd' => user_pw, 'wp-submit' => '로그인', 'redirect_to' => url+'/wp-admin/', 'testcookie' => 1} @header_value = { 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7', 'Cache-Control' => 'max-age=0', 'Connection' => 'keep-alive', 'Content-Type' => 'application/x-www-form-urlencoded', 'Host' => url.split('//')[1], 'Origin' => url, 'Referer' => url+'/wp-login.php?loggedout=true&wp_lang=ko_KR', 'Upgrade-Insecure-Requests' => 1, 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36' } http = HTTP.headers(@header_value).post(url+'/wp-login.php', :form => @form2) answer = Hash.new @cookie2 = '' http..each do |v| @cookie2 += v.to_s.split('=')[0] + '=' + v.to_s.split('=')[1] +'; ' answer[v.to_s.split('=')[0]] = v.to_s.split('=')[1] end puts answer @cookie = answer return answer end |
Instance Method Details
#change_url(url) ⇒ Object
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 |
# File 'lib/deltago.rb', line 1741 def change_url(url) begin http = HTTP.post('https://linkchanger-vfllz.run.goorm.io/action', :json => {'url' => url}) rescue puts '링크체인저 http 일시적 error 10 초후 재시도' sleep(10) retry end json = JSON.parse(http.to_s) return json['result'] end |
#update(product, url_memory, title, text_top, text_bottom, add_text, add_text_check, category, tag_setting, search, url_change_check, proxy_check, proxy_ip) ⇒ Object
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 |
# File 'lib/deltago.rb', line 1596 def update(product, url_memory, title, text_top, text_bottom, add_text, add_text_check, category, tag_setting, search, url_change_check, proxy_check, proxy_ip) http = HTTP.(@cookie).get(@url+'/wp-admin/post-new.php') http..each do |v| @cookie2 += v.to_s.split('=')[0] + '=' + v.to_s.split('=')[1] + '; ' @cookie[v.to_s.split('=')[0]] = v.to_s.split('=')[1] end noko = Nokogiri::HTML(http.to_s) wpnonce2 = noko.to_s.split('_wpnonce":"')[1].split('"')[0] puts category cmm = Hash.new giri = noko.xpath('//*[@id="categorychecklist"]').to_s.split('<li') giri.shift giri.each do |kk| name = kk.split('in-category')[1].split('>')[1].split('<')[0].split(' ').join('').split('"').join('').force_encoding('utf-8') value = kk.split('value="')[1].split('"')[0] cmm[name] = value.to_i end puts cmm if category == '새 카테고리 이름' category_value = 1 else begin category_value = cmm[category.to_s.force_encoding('utf-8')].to_i rescue => exception puts exception category_value = 1 end end vv2 = '<div style="text-align: center;" align="center">'+text_top+'</div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' product.each do |dd| link_url = url_memory[dd['productId']] if url_change_check link_url = change_url(link_url) end vv = '<a href="'+link_url+'"><img class="aligncenter size-full wp-image-175" src="'+word_image_update(dd['image'], wpnonce2 , noko.xpath('//*[@id="post_ID"]').to_s.split('value="')[1].split('"')[0], dd['productId'])+'" alt="" width="410" height="410" /></a>' vv = vv+ '<div style="text-align: center;" align="center"><span style="font-size: 18pt;">'+dd['title']+'</span></div>' vv = vv+ '<div style="text-align: center;" align="center"><span style="font-size: 18pt; color: #ff4b4b;">'+dd['salesPrice'].to_s+' 원</span></div>' vv = vv+ '<div style="text-align: center;" align="center"><span style="font-size: 10pt;">무료배송</span></div>' vv = vv+ '<p style="font-size: 13pt; text-align: center;" align="center"><a style="text-align: center;" href="'+link_url+'"><span style="font-size: 18pt;">상품보기</span></a></p>' vv2 += vv vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' end vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center"> </div><br>' vv2 += '<div style="text-align: center;" align="center">'+text_bottom+'</div><br>' hidden_text = '<canvas width="0" height="0"><table width="165" style="width: 124pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"><tbody><tr height="22" style="height: 16.5pt;"><td width="165" height="22" style="width: 124pt; text-align: center; font-size: 8pt; vertical-align: bottom; white-space: nowrap;"> ' hidden_text2 = '<div id="ssp-bottom"></div></td></tr></tbody></table></canvas>' if add_text_check vv2 += '<div style="text-align: center;" align="center">'+hidden_text+add_text+hidden_text2+'</div><br>' else vv2 += '<div style="text-align: center;" align="center">'+add_text+'</div><br>' end time = Time.now.to_s.split(' ')[0] time2 = Time.now.to_s.split(' ')[1] data2 = Hash.new data2['_wpnonce'] = noko.xpath('//*[@id="_wpnonce"]').to_s.split('value="')[1].split('"')[0] data2['_wp_http_referer'] = '/wp-admin/post.php?post='+noko.xpath('//*[@id="post_ID"]').to_s.split('value="')[1].split('"')[0]+'&action=edit' data2['user_ID'] = 1 data2['action'] = 'editpost' data2['originalaction'] = 'editpost' data2['post_author'] = 1 data2['post_type'] = 'post' data2['original_post_status'] = 'draft' data2['referredby'] = @url+'/wp-admin/edit.php' data2['post_ID'] = noko.xpath('//*[@id="post_ID"]').to_s.split('value="')[1].split('"')[0] data2['post_title'] = title data2['content'] = vv2 data2['hidden_post_status'] = 'draft' data2['post_status'] = 'draft' data2['hidden_post_visibility'] = 'public' data2['visibility'] = 'public' data2['meta-box-order-nonce'] = noko.xpath('//*[@id="meta-box-order-nonce"]').to_s.split('value="')[1].split('"')[0] data2['closedpostboxesnonce'] = noko.xpath('//*[@id="closedpostboxesnonce"]').to_s.split('value="')[1].split('"')[0] data2['samplepermalinknonce'] = noko.xpath('//*[@id="samplepermalinknonce"]').to_s.split('value="')[1].split('"')[0] data2['_ajax_nonce-add-category'] = noko.xpath('//*[@id="_ajax_nonce-add-category"]').to_s.split('value="')[1].split('"')[0] data2['_ajax_nonce-add-meta'] = noko.xpath('//*[@id="_ajax_nonce-add-meta"]').to_s.split('value="')[1].split('"')[0] data2['mm'] = time.split('-')[1] data2['jj'] = time.split('-')[2] data2['aa'] = time.split('-')[0] data2['hh'] = time2.split('-')[0] data2['mn'] = time2.split('-')[1] data2['ss'] = time2.split('-')[2] data2['hidden_mm'] = data2['mm'] data2['cur_mm'] = data2['mm'] data2['hidden_jj'] = data2['jj'] data2['cur_jj'] = data2['jj'] data2['hidden_aa'] = data2['aa'] data2['cur_aa'] = data2['aa'] data2['hidden_hh'] = data2['hh'] data2['cur_hh'] = data2['hh'] data2['hidden_mn'] = data2['mn'] data2['cur_mn'] = data2['mn'] data2['original_publish'] = '공개' data2['publish'] = '공개' data2['post_format'] = 0 data2['post_category[]'] = 0 data2['post_category[]'] = category_value data2['newcategory'] = '새 카테고리 이름' data2['newcategory_parent'] = -1 data2['_thumbnail_id'] = -1 data2['advanced_view'] = 1 data2['comment_status'] = 'open' data2['ping_status'] = 'open' data2['post_author_override'] = 1 if tag_setting data2['tax_input[post_tag]'] = search end puts data2 begin if proxy_check begin http = HTTP.via(proxy_ip.split(':')[0], proxy_ip.split(':')[1].to_i).(@cookie).post(@url+'/wp-admin/post.php', :form => data2) rescue puts proxy_ip.to_s+' proxy error 프록시 없이 업로드' http = HTTP.(@cookie).post(@url+'/wp-admin/post.php', :form => data2) end else http = HTTP.(@cookie).post(@url+'/wp-admin/post.php', :form => data2) end rescue puts '워드프레스 포스팅중 http error 10초후 재시도' sleep(10) retry end puts http.to_s end |
#word_image_update(image_path, wpnonce, post_id, product_id) ⇒ Object
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 |
# File 'lib/deltago.rb', line 1546 def word_image_update(image_path, wpnonce, post_id, product_id) begin http_image = HTTP.get(image_path.to_s.split('212x212').join('500x500')) rescue puts '쿠팡 이미지 가저오는중 http error 10초후 재시도' sleep(10) retry end File.open('./image/'+product_id.to_s+'.jpg', 'wb') do |f| f.write(http_image.body) end file_size = File.size('./image/'+product_id.to_s+'.jpg') @h = Hash.new @h['Host'] = @url.split('//')[1] @h['Accept'] = '*/*' @h['Connection'] = 'keep-alive' @h['Accept-Encoding'] = 'gzip, deflate, br' @h['Accept-Language'] = 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7' @h['Content-Length'] = File.size('./image/'+product_id.to_s+'.jpg')+602 @h['Content-Type'] = 'multipart/form-data; boundary=----WebKitFormBoundaryNbi1Vusy7cc25XJq' @h['Origin'] = @url @h['Referer'] = @url+'/wp-admin/post-new.php' @h['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36' puts @cookie2 @h['Cookie'] = @cookie2 image_json = { 'name' => product_id.to_s+'.jpg', 'action' => 'upload-attachment', '_wpnonce' => wpnonce, 'post_id' => post_id.to_i, 'async-upload' => File.new('./image/'+product_id.to_s+'.jpg') } puts image_json puts @url.split('ttps://').join('ttp://')+'/wp-admin/async-upload.php' begin r = RestClient.post(@url.split('ttps://').join('ttp://')+'/wp-admin/async-upload.php', image_json ,headers=@h) rescue puts '워드프레스 이미지 올리는중 http error 10초후 재시도' sleep(10) retry end json = JSON.parse(r.body) return json['data']['url'] end |