Skip to content

Commit 8e48aad

Browse files
committed
tk
1 parent a475601 commit 8e48aad

File tree

4 files changed

+565
-0
lines changed

4 files changed

+565
-0
lines changed

006-TikTok/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,23 @@
99
2. 使用[uiautomator2](https://github.com/openatx/uiautomator2) 开源库。
1010
3. 借助:weditor 来获取元素(xpath等)。
1111

12+
13+
## seo
14+
```
15+
1、重量副词词汇
16+
https://gist.github.com/mkulakowski2/4289437
17+
18+
2、查看网站排名
19+
https://www.sdwebseo.com/googlerankcheck/
20+
21+
3、看看google浏览器中我的排名,如:
22+
https://www.google.com/search?q=giant stuffed animal caterpillar&num=10&gl=US
23+
https://www.google.com/search?q=4 foot stuffed panda bear&num=100&gl=US
24+
25+
4、获取外链
26+
帮记者一个小忙,获取优质的外链:http://app.helpareporter.com/Pitches
27+
https://www.seoactionblog.com/haro-link-building-strategy/
28+
29+
```
30+
1231
> 其他:注意需要把电脑要把代理关掉
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
@Description: 实现从excel文件获取关键词进行翻译后写入新文件
5+
@Date :2021/10/22
6+
@Author :xhunmon
7+
8+
"""
9+
10+
import json
11+
import os
12+
import os.path
13+
import random
14+
import time
15+
16+
import chardet
17+
import pandas as pd
18+
import requests
19+
20+
import file_util as futls
21+
from my_fake_useragent import UserAgent
22+
23+
24+
class GTransfer(object):
25+
def __init__(self, file):
26+
self.file = file
27+
self._ua = UserAgent()
28+
self._agent = self._ua.random() # 随机生成的agent
29+
self.USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
30+
self._headers = {"user-agent": self.USER_AGENT, 'Connection': 'close'}
31+
32+
def request(self, url, allow_redirects=False, verify=False, proxies=None, timeout=8):
33+
"""最终的请求实现"""
34+
requests.packages.urllib3.disable_warnings()
35+
if proxies:
36+
return requests.get(url=url, headers=self._headers, allow_redirects=allow_redirects, verify=verify,
37+
proxies=proxies, timeout=timeout)
38+
else:
39+
return requests.get(url=url, headers=self._headers, allow_redirects=allow_redirects, verify=verify,
40+
timeout=timeout)
41+
42+
def search_page(self, url, pause=3):
43+
"""
44+
Google search
45+
:param query: Keyword
46+
:param language: Language
47+
:return: result
48+
"""
49+
time.sleep(random.randint(1, pause))
50+
try:
51+
r = self.request(url)
52+
print('resp code=%d' % r.status_code)
53+
if r.status_code == 200:
54+
charset = chardet.detect(r.content)
55+
content = r.content.decode(charset['encoding'])
56+
return content
57+
elif r.status_code == 301 or r.status_code == 302 or r.status_code == 303:
58+
location = r.headers['Location']
59+
time.sleep(random.randint(1, pause))
60+
return self.search_page(location)
61+
return None
62+
except Exception as e:
63+
print(e)
64+
return None
65+
66+
def transfer(self, content):
67+
# url = 'http://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=zh-CN&q=' + content
68+
url = 'http://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=zh-CN&tl=en&q=' + content
69+
try:
70+
cache = futls.read_json('lib/cache.json')
71+
for c in cache:
72+
if content in c:
73+
print('已存在,跳过:{}'.format(content))
74+
return c.get(content)
75+
except Exception as e:
76+
pass
77+
try:
78+
result = self.search_page(url)
79+
trans = json.loads(result)['sentences'][0]['trans']
80+
# 解析获取翻译后的数据
81+
# print(result)
82+
print(trans)
83+
self.local_cache.append({content: trans})
84+
futls.write_json(self.local_cache, self.file)
85+
# 写入数据吗?下次直接缓存取
86+
except Exception as e:
87+
print(e)
88+
return self.transfer(content)
89+
return trans
90+
91+
def transfer_list(self, lists):
92+
self.local_cache = []
93+
for c in lists:
94+
self.transfer(c)
95+
96+
97+
# http://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=zh-CN&q=what
98+
99+
100+
if __name__ == '__main__':
101+
files = next(os.walk('xxx/folder'))[2]
102+
results = []
103+
for f in files:
104+
name, ext = os.path.splitext(f)
105+
if len(name) > 0 and len(ext):
106+
results.append(name)
107+
g = GTransfer('xxx/en.json')
108+
g.transfer_list(results)

006-TikTok/img_2_webp.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
@Description: WordPress 站点 将图片转 webp 格式,实现内容重组
5+
@Date :2022/10/12
6+
@Author :xhunmon
7+
8+
"""
9+
10+
11+
import os
12+
13+
14+
def get_contain_pics(folder, content):
15+
files = next(os.walk(folder))[2]
16+
results = []
17+
for f in files:
18+
name, ext = os.path.splitext(f)
19+
if len(name) < 1 or len(ext) < 1 or '.json' == str(ext) or '.txt' == str(ext): # 非视频文件
20+
continue
21+
if content in f:
22+
results.append(f)
23+
return results
24+
25+
26+
def convert_pic_to_webp(folder, sku, pic_files, t, key1, key2, key3, youtube_num):
27+
dst_folder = os.path.join('data', sku)
28+
desc_links = []
29+
desc_links.append(
30+
'<div align="center"><iframe width="370" height="658" src="https://www.youtube.com/embed/{}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>\n'.format(
31+
youtube_num))
32+
desc_links.append(
33+
'<div align="center"><a href="https://www.youtube.com/channel/UCm2yBXcNJUjYDMl3yE8Ib7w">more video with youtube >></a></div>\n')
34+
if not os.path.exists(dst_folder):
35+
os.makedirs(dst_folder)
36+
# TODO - 上传日期需要注意 月份
37+
full_url = '<img class="aligncenter size-full wp-image-1376" src="https://www.foryoutoy.com/wp-content/uploads/2022/05/{}" alt="{}" width="{}" height="{}" /> \n'
38+
tail = '''
39+
<h2>key1 Design Philosophy</h2>
40+
<strong>1st: Ideal Size </strong>
41+
key1 for girls are great companions, are filled with pp cotton. key2 are many sizes to choose from.This soft friend is irresistible! Anirollz got their name from being key3 shaped like rolls, and they are pure squishy fun.
42+
43+
<strong>2nd: Fine Workmanship </strong>
44+
The soft fleece fabric, exquisite embroidery, special color, and full filling of various parts. Therefore, the bear stuffed animal funny plush toy look more lovely and texture. So silky smooth plush toys, you'll never want to let go!
45+
46+
<strong>3rd: Wide Range Of Uses </strong>
47+
key2 can meet different needs. For example, put on the bed, car, sofa for holding, lying down, leaning. The cuddle key1 is soft and comfortable. Therefore, you can use this key1 as your sleeping partner!
48+
49+
<strong>4th: Perfect Gift </strong>
50+
Our key1 will be loved by kids and adults like. For instance, It's a great gift for family or friends at Christmas, Thanksgiving, birthday, graduation or Valentine's day.
51+
52+
<strong>5th: Develop Empathy And Social Skills </strong>
53+
With a cuddling, comforting plush toy companion. It also helps to develop empathy and social skills, and not only stimulates children's imagination and interest in the animal world. And by taking care of their key2 for kids, they build bridges with their friends in the future.in addition, plush toys are the perfect companions for kids three and older and add a unique decorative touch to any nursery, bedroom, or playroom!
54+
55+
<h2>key2 Buyer notice</h2>
56+
<strong>1st: About hair removal</strong>
57+
Did you notice hair loss after receiving the goods? Don't worry, Our giant stuffed animal toys don't shed hair themselves.Because it is a new product, it will have a little floating hair and filling fiber, after you get it, tap it a few times, shake it a few times. it will remove the floating hair.
58+
59+
<strong>2nd: About size</strong>
60+
All products are measured in kind, and the key2 itself is soft and will have a certain error (about 3 cm).
61+
62+
<strong>3rd: About packaging</strong>
63+
We exhaust part of the air for packaging, because key1 itself is relatively large. Only after taking the time to transport can the product be better protected, so when you receive the product, it is slightly off
64+
the description. Small or a little wrinkled, please don't be surprised. because this is a normal phenomenon, shake a few times after opening, under the sun expose for half an hour and recover immediately!
65+
66+
<h2>Our guarantee</h2>
67+
<h3>Insurance</h3>
68+
Each order includes real-time tracking details and insurance.
69+
<h3>Order And Safe</h3>
70+
We reps ready to help and answer any questions, you have within a 24 hour time frame, 7 days a week. We use state-of-the-art SSL Secure encryption to keep your personal and financial information 100% protected.
71+
72+
<h2>Other aspects</h2>
73+
we’re constantly reinventing and reimagining our key3. If you have feedback you would like to share with us, <a href="/contact">please contact us</a>! We genuinely listen to your suggestions when reviewing our existing toys as well as new ones in development. And are you looking for wholesale plush doll for your school or church carnival? We have the perfect mix of darling stuffed toys for carnival prizes all sold at wholesale prices! We have everything from small stuffed animals such as key1 & dogs, fish, turtles, apes, owls, sharks, & bugs to big stuffed doll such as our large stuffed toy frog and our lovable, key3 and puppy dog!
74+
75+
<img class="aligncenter size-full wp-image-1043" src="https://www.foryoutoy.com/wp-content/uploads/2022/04/shoppingtell-3.webp" alt="large stuffed animals for adults and kids" width="470" height="113" />
76+
'''
77+
tail = tail.replace('key1', key1).replace('key2', key2).replace('key3', key3)
78+
for i in range(0, len(pic_files)):
79+
f = pic_files[i]
80+
src = os.path.join(folder, f)
81+
# dst_name = '{}-m-{}{}'.format(sku, i + 1, ext)
82+
dst_name = '{}-{}-{}.webp'.format(sku, t, i + 1) # 更新至webp
83+
dst = os.path.join(dst_folder, dst_name)
84+
from PIL import Image
85+
im = Image.open(src) # 读入文件
86+
print(im.size)
87+
width = 500
88+
if im.size[0] > width:
89+
h = int(width * im.size[1] / im.size[0])
90+
print(h)
91+
im.thumbnail((width, h), Image.ANTIALIAS) # 重新设置图片大小
92+
im.save(dst) # 保存
93+
print(dst)
94+
if i < 1:
95+
alt_key = key3
96+
elif i < 3:
97+
alt_key = key2
98+
else:
99+
alt_key = key1
100+
if t == 'd':
101+
size = Image.open(dst).size
102+
desc_links.append(full_url.format(dst_name, alt_key, size[0], size[1]))
103+
if t == 'd':
104+
with open(os.path.join('data/desc-html', '{}.txt'.format(sku)), mode='w', encoding='utf-8') as f:
105+
for link in desc_links:
106+
f.write(link)
107+
f.write('\n')
108+
f.write(tail)
109+
f.close()
110+
111+
112+
def deal_sku(folder, sku, key1, key2, key3, youtube_num):
113+
folder = os.path.join(folder, sku)
114+
main_pics = sorted(get_contain_pics(folder, '主图'))
115+
desc_pics = sorted(get_contain_pics(folder, '详情'))
116+
convert_pic_to_webp(folder, sku, main_pics, 'm', key1, key2, key3, youtube_num)
117+
convert_pic_to_webp(folder, sku, desc_pics, 'd', key1, key2, key3, youtube_num)
118+
119+
120+
def deal_sku_list():
121+
folder = 'xxx/SKU/'
122+
deal_sku(folder, 'FYTA032DX', 'elephant plush toy', 'stuffed animal elephant', 'elephant stuffed toy', '4kB0ZJBmMkU') # 奶瓶大象
123+
124+
125+
def convert_2_webp(src, dst):
126+
from PIL import Image
127+
im = Image.open(src) # 读入文件
128+
print(im.size)
129+
# width = 500
130+
# if im.size[0] > width:
131+
# h = int(width * im.size[1] / im.size[0])
132+
# print(h)
133+
# im.thumbnail((width, h), Image.ANTIALIAS) # 重新设置图片大小
134+
im.save(dst) # 保存
135+
136+
137+
def convert_folder(src_folder, dst_folder):
138+
files = next(os.walk(src_folder))[2]
139+
for f in files:
140+
if str(f).startswith('.'):
141+
continue
142+
name, ext = os.path.splitext(f)
143+
convert_2_webp(os.path.join(src_folder, f), os.path.join(dst_folder, '{}.webp'.format(name)))
144+
145+
146+
'''
147+
操作说明:
148+
一:使用Fatkun工具下载图片后进行刷选
149+
1、主图主要4张
150+
2、详情图看情况删除一些,最好保留产品尺寸相关说明的图,正常不会超过10张
151+
二:使用本脚本进行进图压缩以及格式转换(压缩了10倍左右)
152+
1.本脚本将图片宽带缩小至500,高度等比例缩小
153+
2.本脚本将jpg、png格式转换成webp格式
154+
三:新建产品编辑
155+
1.本脚本生成描述图片连接,直接拷贝过去
156+
2.将变量尺寸属性值数字后面加上cm
157+
3.两种产品,定价范围
158+
A. 长条(如:FYTA004BR,长条兔子),属性名称:Long
159+
70cm 18~21
160+
90cm 35~40
161+
110cm 60~70
162+
130cm 90~100
163+
150cm 120~130
164+
B. 圆形(如:FYTA001SP,奶瓶猪),属性名称:Height
165+
35cm 30~35
166+
45cm 55~59
167+
55cm 80~88
168+
65cm 120~130
169+
75cm 160~180
170+
'''
171+
if __name__ == '__main__':
172+
# deal_sku_list()
173+
convert_folder('xxx/png', 'xxx/webp')
174+
175+
#Best Stuffed Pig Toys With A Hat

0 commit comments

Comments
 (0)