This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Convert a file from one encoder to another | |
usage: python convert_encoding.py 'target encoding' 'source file' 'target file' | |
example: python convert_encoding.py 'utf-8' 'file.html' 'file-utf8.html' | |
""" | |
import sys | |
from chardet import detect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
def find_duplicates_in_list(list_to_check: list) -> list: | |
"""Finds duplicate / multiple appearances in a given list, | |
returns a list with the duplicate elements | |
:param list_to_check: list to check for duplicate elements | |
:return: a list with the elements which appeared in the list more than one time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten_nested_lists(list_of_lists: list) -> list: | |
"""Flatten a given list which might contains nested lists | |
and returns one flat list with all elements. | |
:param list_of_lists: list which might have nested lists as elements | |
:return: a list with all elements as flatten content | |
""" | |
for item in list_of_lists: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""With this script you can access Confluence via REST-API to create, modify or delete pages. | |
An auth file for the Confluence authorization is needed. | |
You can create this file with the script create_authorization.py.""" | |
import datetime | |
from os.path import exists | |
import json | |
import requests | |
URL_BASE = 'https://<your-confluence-url>/rest/api/content' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
from datetime import date | |
from enum import IntEnum | |
class Weekday(IntEnum): | |
MONDAY = 0 | |
TUESDAY = 1 | |
WEDNESDAY = 2 | |
THURSDAY = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_leap_year(year: int) -> bool: | |
"""Function determined if the given year is a leap year or not. | |
:param year: the year to be checked. | |
:return: True, if the year is a leap year. | |
False, if the year is no leap year. | |
""" | |
return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterable | |
def parse_ranges(range_string: str) -> Iterable[int]: | |
"""This generator function parses a given string for ranges of numbers, | |
which are separated by a comma, | |
and return the range as single numbers. | |
:param range_string - string which contains one or more range(s) of numbers, e.g. '0, 4-8, 20->exit, 43-45' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import types | |
from typing import Sequence | |
def tail_of_sequence(sequence: Sequence, number: int) -> Sequence: | |
"""Returns n elements from a given sequence, counted from the end of the sequence. | |
:param sequence - sequence which elements are been filtered | |
:param number - number of elements which will be returned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def alphanumeric_sort(alphanumeric_list): | |
"""Returns a given list in correct alphanumeric sort, | |
e.g. 1, 2, 3, 10, 21 instead of 1, 10, 2, 21, 3 | |
:return sorted alphanumeric list | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
'''Beispiele für Zugriffsmöglichkeiten auf HTML-Code, | |
der per request geholt und mit BeautifulSoup aufbereitet wurde. | |
Original-Doku von BeautifulSoup unter https://www.crummy.com/software/BeautifulSoup/bs4/doc/# | |
Dieses Skript enthält nur ein paar Basis-Befehle, um die Syntax im praktischen Beispiel zu zeigen. | |
Die Befehle sollten in eigene Skripte übernommen, und dort entsprechend angepasst werden. | |
Wenn man dieses Skript startet, sollte man die meisten print-Befehle kommentieren, | |
ansonsten wird die Ausgabe zu umfangreich und unübersichtlich. |