I have this time command, and I want it so that when I say p!time, it would say PST time:, EST time:, etc
if message.content.startswith('p!time'):
timestamp = datetime.now()
await message.channel.send(timestamp)
await message.channel.send(timestamp.strftime(r"%I:%M %p"))
#now idk what to do
You need to change timezone, it can be done using a library called pytz
$ pip install pytz
Code:
import pytz
from datetime import datetime
if message.content.startswith('p!time'):
timestamp = datetime.now()
pst = pytz.timezone('US/Pacific')
est = pytz.timezone('US/Eastern')
msg = f"PST Time: {timestamp.astimezone(pst).strftime("%I:%M %p")}, EST Time: {timestamp.astimezone(est).strftime("%I:%M %p")}"
await message.channel.send(msg)
Related
I'm trying to switch from discord.py to pycord since I heard that they don't support slash commands, and while defining simple commands. I keep getting this great Traceback
`
Traceback (most recent call last):
File "c:\Users\****\source\repos\DBot\main.py", line 16, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
`
This is my code up until now.
`
import discord
import os
from dotenv import load_dotenv
# importing environmental vars
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("DISCORD_GUILD")
APP_ID = os.getenv("APP_ID")
PUB_KEY = os.getenv("PUBLIC_KEY")
GUILD_ID = os.getenv("GUILD_ID")
GENERAL_CHAN_ID = os.getenv("CHANNEL_GENERAL_ID")
#finished importing .env vars
#class for client
bot = discord.Bot()
#bot.slash_command()
async def hello(ctx, name: str = None):
name = name or ctx.author.name
await ctx.respond(f"Hello {name}!")
#bot.user_command(name="Say Hello")
async def hi(ctx, user):
await ctx.respond(f"{ctx.author.mention} says hello to {user.name}!")
bot.run("token")
`
I have py-cord version 2.3.2 so I know it's not version issue
I just started using py-cord so I have no idea what I'm doing except ctrl c ctrl v-ing examples from their documentation page to see if it works
Help is greatly appreciated!!!
I had the same mistake.
What fixed it for me was:
Go into your project directory.
pip install py-cord if this doesn't work, try step 3.
pip install py-cord==2.0.0rc1 this is a beta version of pycord.
Im upgrading my system from React 15.4 to React 17.0.2
Im having an issue with React-Widgets
Warning: Failed prop type: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker). However there is no localizer set. Please configure a localizer.
So im not sure how to handle this.
I installed the following for this.
"moment": "^2.29.1",
"react-widgets": "^4.6.1",
"react-widgets-moment": "^5.0.11",
"react-widgets-moment-localizer": "^1.0.2",
When I start the program I am met with the error above.
This is the attempt to set the localizer.
import MomentLocalizer from "react-widgets-moment-localizer";
import dateHandler, {parseDate} from './dateHandler'
import {DateTimePicker, SelectList, DropdownList} from 'react-widgets';
// moment.locale('en');
// MomentLocalizer(moment);
moment.locale('en')
const localizer = new MomentLocalizer(moment)
But results in the error mentioned.
I also looked at the documentation (http://jquense.github.io/react-widgets/docs/localization)
But obviously failed to get it going.
Any help would be appreciated.
For me what worked was to copy the old localizers folder into the React-widgets tree.
../react-widgets/lib/localizers
Then invoking it in the same way as I used to.
import moment from 'moment';
import momentLocalizer from 'react-widgets/lib/localizers/moment';
import {DateTimePicker, SelectList, DropdownList} from 'react-widgets';
// moment.locale('en');
// momentLocalizer(moment);
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
doy: 4 // First week of year must contain 4 January (7 + 1 - 4)
}}); //this is to change the first day of the week from sunday to monday
momentLocalizer(moment);
I am using jest and react.
I have the following test:
import sut from '../../utils/timeFormater';
describe('timeFormater utils ', () => {
test('hours should be 09 if the getHours method return number less then 10', () => {
const date = new Date('Mon Feb 08 2021 09:18:11 GMT+0100 (Central European Standard Time');
const result = sut(date);
expect(result.split(':')[0]).toBe('09');
});
});
after my deployment on the server - there the time is one hour earlier so
when i expect - expect(result.split(':')[0]).toBe('09');
it is working on my local machine
but it is not working on the deployed serrver - there the tests are failing because there
it receives 08 instead 09 for
const date = new Date('Mon Feb 08 2021 09:18:11 GMT+0100 (Central European Standard Time');
how can i solve this issue ?
I am new in Play Framework (Scala) and need some advise.
I use Scala 2.12 and Play Framework 2.6.20. I need to use several databases in my project. Right now I connected MySQL database as it says in documentation. How correctly connect project to remote Oracle 12g database?
application.conf:
db {
mysql.driver = com.mysql.cj.jdbc.Driver
mysql.url = "jdbc:mysql://host:port/database?characterEncoding=UTF-8"
mysql.username = "username"
mysql.password = "password"
}
First of all to lib folder I put ojdbc8.jar file from oracle website.
Then add libraryDependencies += "com.oracle" % "ojdbc8" % "12.1.0.1" code to sbt.build file. Finally I wrote settings to aplication.conf file.
After that step I notice error in terminal:
[error] (*:update) sbt.ResolveException: unresolved dependency: com.oracle#ojdbc8;12.1.0.1: not found
[error] Total time: 6 s, completed 10.11.2018 16:48:30
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
EDIT:
application.conf:
db {
mysql.driver = com.mysql.cj.jdbc.Driver
mysql.url = "jdbc:mysql://#host:#port/#database?characterEncoding=UTF-8"
mysql.username = "#username"
mysql.password = "#password"
oracle.driver = oracle.jdbc.driver.OracleDriver
oracle.url = "jdbc:oracle:thin:#host:#port/#sid"
oracle.username = "#username"
oracle.password = "#password"
}
ERROR:
play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
1) No implementation for play.api.db.Database was bound.
while locating play.api.db.Database
for the 1st parameter of controllers.GetMarkersController.<init>(GetMarkersController.scala:14)
while locating controllers.GetMarkersController
for the 7th parameter of router.Routes.<init>(Routes.scala:45)
at play.api.inject.RoutesProvider$.bindingsFromConfiguration(BuiltinModule.scala:121):
Binding(class router.Routes to self) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
GetMarkersController.scala:
package controllers
import javax.inject._
import akka.actor.ActorSystem
import play.api.Configuration
import play.api.mvc.{AbstractController, ControllerComponents}
import play.api.libs.ws._
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future, Promise}
import services._
import play.api.db.Database
class GetMarkersController #Inject()(db: Database, conf: Configuration, ws: WSClient, cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
def getMarkersValues(start_date: String, end_date: String) = Action.async {
getValues(1.second, start_date: String, end_date: String).map {
message => Ok(message)
}
}
private def getValues(delayTime: FiniteDuration, start_date: String, end_date: String): Future[String] = {
val promise: Promise[String] = Promise[String]()
val service: GetMarkersService = new GetMarkersService(db)
actorSystem.scheduler.scheduleOnce(delayTime) {
promise.success(service.get_markers(start_date, end_date))
}(actorSystem.dispatcher)
promise.future
}
}
You cannot access Oracle without credentials. You need to have an account with Oracle. Then add something like the following to your build.sbt file
resolvers += "Oracle" at "https://maven.oracle.com"
credentials += Credentials("Oracle", "maven.oracle.com", "username", "password")
More information about accessing the OTN: https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9012
If you have the hard coded jar, you don't need to include as a dependency. See unmanagedDependencies https://www.scala-sbt.org/1.x/docs/Library-Dependencies.html
I have been trying out DroneKit Python and have been working with some of the examples provided. Having got to a point of some knowledge of working with DroneKit I have started writing some python code to perform a single mission. My only problem is that the start location for my missions are always defaulting to Lat = -35.3632605, Lon = 149.1652287 - even though I have set the home location to the following:
start_location = LocationGlobal(51.945102, -2.074558, 10)
vehicle.home_location = start_location
Is there something else in the api I am missing out on doing in order to set the start location of the drone in the simulation environment?
Problem solved by starting the DroneKit SITL using the following command:
dronekit -sitl copter --home=51.945102,-2.074558,0,180
This now starts the simulation of the drone in the desired location and not the default location in Australia!
You can actually start the SITL with custom args from python script by adding the args to the SITL launch code, here a simple example:
from dronekit_sitl import SITL
from dronekit import Vehicle, connect
sitl = SITL()
sitl.download('copter', '3.3', verbose=True)
sitl_args = ['-I0', '--model', 'quad', '--home=51.945102,-2.074558,0,180']
sitl.launch(sitl_args, await_ready=True, restart=True)
connection_string = 'tcp:127.0.0.1:5760'
print("Connecting to vehicle on: %s" % connection_string)
vehicle = connect(connection_string, wait_ready=True, baud=57600)