V
V
ValeraShprot2020-02-24 15:25:56
Python
ValeraShprot, 2020-02-24 15:25:56

Gives an error 'str' object is not callable, how to fix it?

Since I have scripts for hosting, when I try to do something with the time, the hosting time is set there (it is in America), I need Moscow time. This is part of the script for the Vkontakte network.

from urllib import request
import requests
import pytz
import datetime
import urllib
import json
import time
import vk

token = "Token"
timeKD = 60 

session = vk.Session(access_token = token)
api = vk.API(session, v = "5.95")

def startStatus():

    moscowtime = str(datetime.datetime.now(pytz.timezone('Europe/Moscow'))) #Ошибки
    fmt = "%Y-%m-%d %H:%M:%S"

    statusOut = api.status.set(text = "Сведения: " + moscowtime(fmt))

while True:
    startStatus()
    print('обновлено')
    time.sleep(timeKD)


I tried to fix it but there are new errors, I ask for help from experts)))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Garbazhiy, 2020-02-24
@WaterWalker

I'm no expert, but try this:

moscowtime = datetime.datetime.now(pytz.timezone('Europe/Moscow'))
fmt = "%d-%m-%Y %H:%M:%S"
statusOut = api.status.set(text = "Сведения: " + str(moscowtime(fmt)))

V
ValeraShprot, 2020-02-24
@ValeraShprot

moscowtime = str(datetime.datetime.now(pytz.timezone('Europe/Moscow')))
fmt = "%d-%m-%Y %H:%M:%S"
statusOut = api.status.set( text = "Time: " + moscowtime)
This works, but you need to show the time in the format "%d-%m-%Y %H:%M:%S"

A
Arkady Illarionov, 2020-02-26
@qark

moscowtime = datetime.datetime.now(pytz.timezone('Europe/Moscow'))
fmt = "%Y-%m-%d %H:%M:%S"
statusOut = api.status.set(text = "Сведения: " + moscowtime.strftime(fmt))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question