Compare commits
11 Commits
0a72912928
...
0.1.0
Author | SHA1 | Date | |
---|---|---|---|
5cf265f09c | |||
91743d1c6d | |||
516e08a707 | |||
ff645425f9 | |||
0f01ef80ec | |||
7ce32bac41 | |||
fa6cb6c65e | |||
84ba9f45fa | |||
409b8d4a2a | |||
000660253e | |||
41571f291a |
22
.drone.yml
Normal file
22
.drone.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build and publish
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: registry.kucharczyk.tech/python-pypi
|
||||
commands:
|
||||
- python -m build
|
||||
- name: publish
|
||||
image: registry.kucharczyk.tech/python-pypi
|
||||
commands:
|
||||
- python -m twine upload -u $USERNAME -p $PASSWORD dist/*
|
||||
environment:
|
||||
USERNAME:
|
||||
from_secret: pypi_username
|
||||
PASSWORD:
|
||||
from_secret: pypi_password
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -138,3 +138,5 @@ dmypy.json
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
testfiles
|
||||
*.csv
|
||||
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"editor.formatOnSave": true,
|
||||
"python.formatting.provider": "black"
|
||||
}
|
15
Pipfile
Normal file
15
Pipfile
Normal file
@ -0,0 +1,15 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
python-frontmatter = "*"
|
||||
durations = "*"
|
||||
|
||||
[dev-packages]
|
||||
black = "*"
|
||||
build = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.10"
|
174
Pipfile.lock
generated
Normal file
174
Pipfile.lock
generated
Normal file
@ -0,0 +1,174 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "4a6a85639db632b62a977f88ab0a77557d1fe6477398675f6d24f006c59c0ff9"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.10"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"durations": {
|
||||
"hashes": [
|
||||
"sha256:820ffe09c390469dc621b6a0aa46d3a624b6dadf09b439e175696b6f6b77ef2f"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.3.3"
|
||||
},
|
||||
"python-frontmatter": {
|
||||
"hashes": [
|
||||
"sha256:766ae75f1b301ffc5fe3494339147e0fd80bc3deff3d7590a93991978b579b08",
|
||||
"sha256:e98152e977225ddafea6f01f40b4b0f1de175766322004c826ca99842d19a7cd"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.0.0"
|
||||
},
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
"sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293",
|
||||
"sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b",
|
||||
"sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57",
|
||||
"sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b",
|
||||
"sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4",
|
||||
"sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07",
|
||||
"sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba",
|
||||
"sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9",
|
||||
"sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287",
|
||||
"sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513",
|
||||
"sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0",
|
||||
"sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0",
|
||||
"sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92",
|
||||
"sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f",
|
||||
"sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2",
|
||||
"sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc",
|
||||
"sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c",
|
||||
"sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86",
|
||||
"sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4",
|
||||
"sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c",
|
||||
"sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34",
|
||||
"sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b",
|
||||
"sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c",
|
||||
"sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb",
|
||||
"sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737",
|
||||
"sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3",
|
||||
"sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d",
|
||||
"sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53",
|
||||
"sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78",
|
||||
"sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803",
|
||||
"sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a",
|
||||
"sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174",
|
||||
"sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==6.0"
|
||||
}
|
||||
},
|
||||
"develop": {
|
||||
"black": {
|
||||
"hashes": [
|
||||
"sha256:07e5c049442d7ca1a2fc273c79d1aecbbf1bc858f62e8184abe1ad175c4f7cc2",
|
||||
"sha256:0e21e1f1efa65a50e3960edd068b6ae6d64ad6235bd8bfea116a03b21836af71",
|
||||
"sha256:1297c63b9e1b96a3d0da2d85d11cd9bf8664251fd69ddac068b98dc4f34f73b6",
|
||||
"sha256:228b5ae2c8e3d6227e4bde5920d2fc66cc3400fde7bcc74f480cb07ef0b570d5",
|
||||
"sha256:2d6f331c02f0f40aa51a22e479c8209d37fcd520c77721c034517d44eecf5912",
|
||||
"sha256:2ff96450d3ad9ea499fc4c60e425a1439c2120cbbc1ab959ff20f7c76ec7e866",
|
||||
"sha256:3524739d76b6b3ed1132422bf9d82123cd1705086723bc3e235ca39fd21c667d",
|
||||
"sha256:35944b7100af4a985abfcaa860b06af15590deb1f392f06c8683b4381e8eeaf0",
|
||||
"sha256:373922fc66676133ddc3e754e4509196a8c392fec3f5ca4486673e685a421321",
|
||||
"sha256:5fa1db02410b1924b6749c245ab38d30621564e658297484952f3d8a39fce7e8",
|
||||
"sha256:6f2f01381f91c1efb1451998bd65a129b3ed6f64f79663a55fe0e9b74a5f81fd",
|
||||
"sha256:742ce9af3086e5bd07e58c8feb09dbb2b047b7f566eb5f5bc63fd455814979f3",
|
||||
"sha256:7835fee5238fc0a0baf6c9268fb816b5f5cd9b8793423a75e8cd663c48d073ba",
|
||||
"sha256:8871fcb4b447206904932b54b567923e5be802b9b19b744fdff092bd2f3118d0",
|
||||
"sha256:a7c0192d35635f6fc1174be575cb7915e92e5dd629ee79fdaf0dcfa41a80afb5",
|
||||
"sha256:b1a5ed73ab4c482208d20434f700d514f66ffe2840f63a6252ecc43a9bc77e8a",
|
||||
"sha256:c8226f50b8c34a14608b848dc23a46e5d08397d009446353dad45e04af0c8e28",
|
||||
"sha256:ccad888050f5393f0d6029deea2a33e5ae371fd182a697313bdbd835d3edaf9c",
|
||||
"sha256:dae63f2dbf82882fa3b2a3c49c32bffe144970a573cd68d247af6560fc493ae1",
|
||||
"sha256:e2f69158a7d120fd641d1fa9a921d898e20d52e44a74a6fbbcc570a62a6bc8ab",
|
||||
"sha256:efbadd9b52c060a8fc3b9658744091cb33c31f830b3f074422ed27bad2b18e8f",
|
||||
"sha256:f5660feab44c2e3cb24b2419b998846cbb01c23c7fe645fee45087efa3da2d61",
|
||||
"sha256:fdb8754b453fb15fad3f72cd9cad3e16776f0964d67cf30ebcbf10327a3777a3"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==22.1.0"
|
||||
},
|
||||
"build": {
|
||||
"hashes": [
|
||||
"sha256:1aaadcd69338252ade4f7ec1265e1a19184bf916d84c9b7df095f423948cb89f",
|
||||
"sha256:21b7ebbd1b22499c4dac536abc7606696ea4d909fd755e00f09f3c0f2c05e3c8"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.7.0"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:6a7a62563bbfabfda3a38f3023a1db4a35978c0abd76f6c9605ecd6554d6d9b1",
|
||||
"sha256:8458d7b1287c5fb128c90e23381cf99dcde74beaf6c7ff6384ce84d6fe090adb"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==8.0.4"
|
||||
},
|
||||
"mypy-extensions": {
|
||||
"hashes": [
|
||||
"sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
|
||||
"sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"
|
||||
],
|
||||
"version": "==0.4.3"
|
||||
},
|
||||
"packaging": {
|
||||
"hashes": [
|
||||
"sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb",
|
||||
"sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==21.3"
|
||||
},
|
||||
"pathspec": {
|
||||
"hashes": [
|
||||
"sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a",
|
||||
"sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"
|
||||
],
|
||||
"version": "==0.9.0"
|
||||
},
|
||||
"pep517": {
|
||||
"hashes": [
|
||||
"sha256:931378d93d11b298cf511dd634cf5ea4cb249a28ef84160b3247ee9afb4e8ab0",
|
||||
"sha256:dd884c326898e2c6e11f9e0b64940606a93eb10ea022a2e067959f3a110cf161"
|
||||
],
|
||||
"version": "==0.12.0"
|
||||
},
|
||||
"platformdirs": {
|
||||
"hashes": [
|
||||
"sha256:7535e70dfa32e84d4b34996ea99c5e432fa29a708d0f4e394bbcb2a8faa4f16d",
|
||||
"sha256:bcae7cab893c2d310a711b70b24efb93334febe65f8de776ee320b517471e227"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2.5.1"
|
||||
},
|
||||
"pyparsing": {
|
||||
"hashes": [
|
||||
"sha256:18ee9022775d270c55187733956460083db60b37d0d0fb357445f3094eed3eea",
|
||||
"sha256:a6c06a88f252e6c322f65faf8f418b16213b51bdfaece0524c1c1bc30c63c484"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==3.0.7"
|
||||
},
|
||||
"tomli": {
|
||||
"hashes": [
|
||||
"sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
|
||||
"sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2.0.1"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
# Example package
|
||||
# `frontmatter-to-csv` - Convert YAML front matter to CSV
|
||||
|
||||
This is a simple example package.
|
||||
This simple Python script will convert fields from the YAML front matter to your specified CSV fields.
|
||||
Optionally, it can transform some of the fields:
|
||||
|
||||
* convert Python lists to comma-joined lists
|
||||
* convert varied human-readable durations to unified unit (hours)
|
65
frontmatter_to_csv/convert.py
Normal file
65
frontmatter_to_csv/convert.py
Normal file
@ -0,0 +1,65 @@
|
||||
"""
|
||||
Convert YAML front matter to CSV
|
||||
"""
|
||||
|
||||
from queue import Empty
|
||||
from typing import Dict
|
||||
from durations import Duration
|
||||
import os
|
||||
import frontmatter
|
||||
import csv
|
||||
|
||||
filtered = dict()
|
||||
fields = {
|
||||
"name": "Name",
|
||||
"playtime": "Playtime",
|
||||
"platform": "Platform",
|
||||
"infinite": "Infinite",
|
||||
"finished": "Finished",
|
||||
"refunded": "Refunded",
|
||||
"dropped": "Dropped",
|
||||
"date-released": "DateReleased",
|
||||
"date-purchased": "DatePurchased",
|
||||
"date-started": "DateStarted",
|
||||
"date-finished": "DateFinished",
|
||||
}
|
||||
|
||||
|
||||
def convert(directory="f", outputfile="test.csv"):
|
||||
if not os.path.isdir(directory):
|
||||
exit(f"The directory {directory} does not exist!")
|
||||
with open(outputfile, "w", newline="") as csvfile:
|
||||
writer = csv.DictWriter(csvfile, fieldnames=fields.values())
|
||||
writer.writeheader()
|
||||
for filename in os.listdir(directory):
|
||||
f = os.path.join(directory, filename)
|
||||
|
||||
if os.path.isfile(f):
|
||||
article = frontmatter.load(f)
|
||||
for field in fields:
|
||||
if field not in article.metadata.keys():
|
||||
newvalue = ""
|
||||
else:
|
||||
newvalue = article.metadata[field]
|
||||
if field == "playtime" and newvalue != 0 and newvalue is not None:
|
||||
if type(newvalue) is dict:
|
||||
totalvalue = 0
|
||||
for key in newvalue:
|
||||
timevalue = Duration(newvalue[key]).to_hours()
|
||||
totalvalue += timevalue
|
||||
newvalue = totalvalue
|
||||
else:
|
||||
timevalue = Duration(newvalue)
|
||||
newvalue = timevalue.to_hours()
|
||||
if type(newvalue) is list:
|
||||
print(
|
||||
f"Field '{field}' for file '{filename}' is a list, joining with commas."
|
||||
)
|
||||
newvalue = ",".join(newvalue)
|
||||
filtered[fields[field]] = newvalue
|
||||
|
||||
writer.writerow(filtered)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
convert()
|
24
setup.cfg
24
setup.cfg
@ -1,24 +1,26 @@
|
||||
[metadata]
|
||||
name = example-pkg-YOUR-USERNAME-HERE
|
||||
version = 0.0.1
|
||||
name = frontmatter-to-csv
|
||||
version = 0.1.0
|
||||
author = Lukáš Kucharczyk
|
||||
author_email = lukas@kucharczyk.xyz
|
||||
description = A small example package
|
||||
description = Convert YAML front matter to CSV
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://git.kucharczyk.xyz/templates/python
|
||||
url = https://git.kucharczyk.xyz/lukas/frontmatter-to-csv
|
||||
project_urls =
|
||||
Bug Tracker = https://git.kucharczyk.xyz/templates/python/issues
|
||||
Bug Tracker = https://git.kucharczyk.xyz/lukas/frontmatter-to-csv/issues
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
License :: OSI Approved :: MIT License
|
||||
Environment :: Console
|
||||
Intended Audience :: End Users/Desktop
|
||||
License :: OSI Approved :: GNU General Public License (GPL)
|
||||
Operating System :: OS Independent
|
||||
Topic :: Utilities
|
||||
|
||||
[options]
|
||||
package_dir =
|
||||
= src
|
||||
packages = find:
|
||||
packages = frontmatter_to_csv
|
||||
python_requires = >=3.6
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
frontmatter-to-csv = frontmatter_to_csv.convert:convert
|
@ -1 +0,0 @@
|
||||
|
Reference in New Issue
Block a user