import sys
import time
from pyquery import PyQuery as pq
tmp = '''---
title: {title}
tag: algorithm
date: {date}
---
## Description
**Difficulty: {difficulty}**
{contents}
## Solution
{% codeblock lang:text %}
{% endcodeblock %}
'''
url = sys.argv[1]
d = pq(url)
get_title = d('.question-title h3').text()
get_difficulty = d('#DescriptionContent .question-info li strong').eq(2).text()
get_filename = url.rstrip('?tab=Description').rstrip('/').split('/')[-1] + '.md'
get_contents = (d('.question-content')
.html(method='html')
.split('<div><p><a href="/subscribe/">Subscribe</a>')[0]
.split('<p><b>Credits:</b>')[0]
.strip())
tmp = tmp.format(
title=get_title,
difficulty=get_difficulty,
contents=get_contents,
date=time.strftime("%F %H:%M:%S", time.localtime()))
file = open(get_filename, 'w')
file.write(tmp)
file.close()
print('Show time:', get_filename)
近期评论