On the 38th Festival, I rely on this trick to make her happy like a queen

As a programmer who has been cut off, I'm sorry, it should be a style here, and it's a little confusing to drink too much.

 

Well let's do it again.

 

As a stylish programmer, we are not the kind of stuffy houses that the outside world said. At this moment, I took another tablespoon of Chuanbei loquat paste and slapped wildly. It is said that this is the current trend in Europe and the United States. For a person of style and taste like me, that's what I have to drink.

Seeing that the festival of half the sky is coming, it seems that the goddess can't take a long holiday, which makes her a little emotional. How can I make my goddess happy? This proposition tortured my already dizzy soul. To tell the truth, my inspiration has been released on Valentine's Day, and with the whirring north wind blowing to distant and strange places.

I was halfway through the class, and when I looked at the log that kept reporting errors, I suddenly had inspiration. I am a senior programmer, comrades, if there is an error, we must trace the source, if there is a bug, we must solve it, and if there is a demand, we must meet the difficulties, comrades!

 

Just do it!

 

I'm ready to do something for me with Watson, the best at artificial intelligence!

Just do it! Do it without hesitation!

 

First, I quietly collected photos carefully taken in the circle of friends of the goddess, and then, using the interface of IBM Watson, I tagged all the pictures. Smart, you must have thought that these labels have been sorted out, and the ones that appear frequently must be the goddess's favorite!

When the results came out, I shed two lines of tears with mixed feelings in my heart...

With tears in my eyes, I looked at the empty bottle of loquat ointment, took a few mouthfuls of wild jelly, looked at the balance of my account, and directly placed an order for the most expensive designer bag I could afford...

The trembling hands can't quell the sin of deleting the code for a long time, the ten lovely fingers in the soul open my favorite entertainment website, it's time to do something for myself...

 

Just do it! Do it without hesitation!

 

The most critical code was typed out involuntarily...


from selenium import webdriver # 获取动态⽹站信息所需要的⼯具

from tqdm import tqdm

url = 'http://jandan.net/ooxx' # ⽬标⽹站

output_dir = './img/' # 图⽚储存⽬录

# ⾃动打开浏览器访问⽬标⽹站

chrome = webdriver.Chrome()

chrome.get(url)分析并获取图⽚的URL

eles = chrome.find_elements_by_tag_name('img')

filter_func = lambda url: 'http://img.jandan.net' in url and '.jpg!custom' in url

img_urls = list(filter(filter_func, [ele.get_attribute('src') for ele in eles]))

img_urls = [img_url.split('!custom')[0] for img_url in img_urls]

chrome.close()

print('URL Count:', len(img_urls))

import json, os, random

from PIL import Image, ImageDraw, ImageFont

from io import BytesIO

from watson_developer_cloud import VisualRecognitionV3 # 调⽤ Watson 视觉识别 API

from urllib.request import urlopen, Request

# ⽣成视觉识别对象

visual_recognition = VisualRecognitionV3(

 '2018-02-07', api_key='4d0add5078762baa390070ac25efdb16236d****')

采集图⽚并调⽤ Watson API 为图⽚打上标签

for i, url in enumerate(tqdm(img_urls, ncols=80)):

 res = Request(url, headers={'User-Agent': 'Chrome 50'})

 img = Image.open(BytesIO(urlopen(res).read()))

 pad = Image.new(mode='RGB', size=(1280, 720), color=random.randint(0, 0XFFFFFF

 pad.paste(img, ((pad.size[0] - img.size[0]) // 2, (pad.size[1] - img.size[1])

 draw = ImageDraw.Draw(pad)

 url_res = visual_recognition.classify(parameters=json.dumps({'url': url}))

 classes = url_res['images'][0]['classifiers'][0]['classes']

 img_desc = ', '.join([item['class']

 for item in sorted(classes, key=lambda a: a['score'], re

 font = ImageFont.truetype('NotoSansCJK-Black.ttc', size=random.randint(48, 64)

 draw.text(

 xy=(random.randint(-pad.size[0] // 10, pad.size[0] // 5),

 random.randint(pad.size[1] // 8, pad.size[1] // 2)),

 text=img_desc, fill=random.randint(0, 0XFFFFFF), font=font)

 pad.save(os.path.join(output_dir, '{:02d}.jpg'.format(i)))

 

For the lovely you, I exhausted my last bit of strength, and I recorded a video tutorial, dedicated to you, to the goddess.

Hit the link below...

https://www.bilibili.com/video/av20426710/

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324447649&siteId=291194637