from datetime import datetime


def get_post_details(res):
    """
    Extract and preprocess selected attributes from a result of a reddit api call (post only, not comments)
    :param
    res: json
        the result of a reddit api call for a random post of a specified subreddit
    :return: dict
        information about the post
    """
    post = res[0]['data']['children'][0]
    reddit_post_id = post['kind'] + '_' + post['data']['id']
    title = post['data']['title']
    subreddit = post['data']['subreddit']
    score = post['data']['score']
    created = datetime.utcfromtimestamp(int(post['data']['created'])).strftime('%Y-%m-%d %H:%M:%S')
    upvote_ratio = post['data']['upvote_ratio']
    permalink = 'https://reddit.com'+post['data']['permalink']
    thumbnail = post['data']['thumbnail']
    total_awards_received = post['data']['total_awards_received']
    num_comments = post['data']['num_comments']
    url = post['data']['url']
    timestamp_accessed = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    return {'title': title, 'score': score, 'created': created, 'upvote_ratio': upvote_ratio,
            'thumbnail': thumbnail, 'url': url, 'subreddit': subreddit,
            'permalink': permalink, 'total_awards_received': total_awards_received, 'num_comments': num_comments,
            'reddit_post_id': reddit_post_id, 'timestamp_accessed': timestamp_accessed}