zdgtl 11 months ago
zdgtl #coding

Time Ago to Date Format Converter

Convert Time Ago Format to Date Format

import sys
from datetime import datetime, timedelta

def parse_time_ago(time_ago_str):
    number, unit, _ = time_ago_str.split()
    number = int(number)

    if "hour" in unit:
        return timedelta(hours=number)
    elif "day" in unit:
        return timedelta(days=number)
    elif "week" in unit:
        return timedelta(weeks=number)
    elif "month" in unit:
        # Approximate month as 30.44 days
        return timedelta(days=number * 30.44)
    elif "year" in unit:
        # Approximate year as 365.25 days
        return timedelta(days=number * 365.25)
    else:
        raise ValueError(f"Unknown time unit: {unit}")

def main(input_file, output_file):
    now = datetime.now()

    with open(input_file, 'r') as f:
        time_ago_list = f.readlines()

    result = []
    for time_ago in time_ago_list:
        time_ago = time_ago.strip()
        try:
            delta = parse_time_ago(time_ago)
            past_date = now - delta
            result.append(f"{time_ago}: {past_date.strftime('%Y-%m-%d %H:%M:%S')}\n")
        except ValueError as e:
            result.append(f"{time_ago}: Error - {str(e)}\n")

    with open(output_file, 'w') as f:
        f.writelines(result)

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python datescript.py ago.txt date.txt")
    else:
        input_file = sys.argv[1]
        output_file = sys.argv[2]
        main(input_file, output_file)
0
372
Bulk Rename File by Powershell

Bulk Rename File by Powershell

1743468932.jpg
zdgtl
11 months ago
Wordpress Auto Post via XMLRPC

Wordpress Auto Post via XMLRPC

1743468932.jpg
zdgtl
11 months ago
Cara Install C9 di Ubuntu

Cara Install C9 di Ubuntu

1743468932.jpg
zdgtl
11 months ago

Check File

This script will help you efficiently check for the existence of file across multiple URLs...

1743468932.jpg
zdgtl
11 months ago
Reverse Complex String Using Regex

Reverse Complex String Using Regex

1743468932.jpg
zdgtl
11 months ago