每天早上,我都会在python上生成一系列图表。为此,我:
我是否可以自动执行此任务并使它每天运行而无需执行步骤1?
答案 0 :(得分:1)
首先创建Exe以避免第一步,并尝试使用Windows Scheduler对其进行调度以每天运行。
**import 'package:galon_app/PlugIn/User.dart';
import 'package:galon_app/pages/maps.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:galon_app/pages/createUser.dart';
import 'NotifOrder.dart';
import 'OnGoingOrder.dart';
import 'Profile.dart';
final googleSignIn = GoogleSignIn();
final StorageReference storageRef = FirebaseStorage.instance.ref();
final userRef = Firestore.instance.collection('users');
final itemnRef = Firestore.instance.collection('item');
final priceRef = Firestore.instance.collection('prices');
User currentUser;
class Home extends StatefulWidget {
final int pageIndex;
Home({
this.pageIndex
});
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool isAuth = false;
PageController pageController;
int pageIndex = 0;
TextEditingController usernmae = TextEditingController();
TextEditingController password = TextEditingController();
@override
void initState() {
// TODO: implement initState
super.initState();
setPageIndex();
pageController = PageController(initialPage: pageIndex, keepPage: true, viewportFraction: 1);
//Checking is User Signed in
googleSignIn.onCurrentUserChanged.listen((account){
handleSignIn(account);
},onError: (err){
print('Error singin: $err');
}
);
//Reauthenticate user when app is opened
googleSignIn.signInSilently(suppressErrors: false).then((account){
handleSignIn(account);
}).catchError((err){
print('Error Signin: $err');
});
}
//Set page index
setPageIndex(){
if(widget.pageIndex != null){
pageIndex = widget.pageIndex;
onPageChanged(pageIndex);
}else{
pageIndex = 0;
}
}
//Login Handle
login(){
googleSignIn.signIn();
}
logout(){
googleSignIn.signOut();
}
handleSignIn(GoogleSignInAccount account){
if(account != null){
setState(() {
isAuth = true;
});
}else{
setState(() {
isAuth = false;
});
}
}
//Home Screen Handle
@override
void dispose() {
pageController.dispose();
super.dispose();
}
//Set on page changed
onPageChanged(int pageIndex){
setState(() {
this.pageIndex = pageIndex;
});
}
//Animated to next page when taped
onTap(int pageIndex){
pageController.animateToPage(
pageIndex,
duration: Duration(milliseconds: 200),
curve: Curves.easeInOut
);
}
//Build UnAuthScreen(If user not logged in or havent sign up yet)
Scaffold buildUnAuthScreen(){
return Scaffold(
body: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).accentColor,
Theme.of(context).primaryColor,
]
)
),child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 150),
Container(
height: 150,
width: 150,
alignment: Alignment.center,
child: Image.asset('assets/galonku_Logo.png'),
),
SizedBox(height:500),
GestureDetector(
onTap: login,
child: Container(
width: 260,
height: 60,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/googleSignIn_button.png'),
fit: BoxFit.cover
)
)
)
)
],
),
)
);
}
//Build AuthScreen (If user already loggedin)
Scaffold buildAuthScreen(){
return Scaffold(
body: PageView(
children: <Widget>[
Maps(),
//OnGoingOrder(),
NotifOrder(),
Profile(),
],
controller: pageController ,
onPageChanged: onPageChanged,
physics: NeverScrollableScrollPhysics(),
),
bottomNavigationBar: CupertinoTabBar(
currentIndex: pageIndex,
onTap: onTap,
activeColor: Colors.grey[100],
inactiveColor: Colors.grey[700],
backgroundColor: Theme.of(context).primaryColor,
items: [
BottomNavigationBarItem(icon: Icon(Icons.shopping_cart)),
BottomNavigationBarItem(icon: Icon(Icons.notifications)),
BottomNavigationBarItem(icon: Icon(Icons.person))
],
)
);
}
@override
Widget build(BuildContext context) {
return isAuth? buildAuthScreen() :buildUnAuthScreen();
}
}**
答案 1 :(得分:0)
您需要创建一个安装了所有依赖项的环境,然后才能通过CronJob运行脚本。 enter link description here
对于Unix:
对于Windows:
虚拟环境:
虚拟环境中的CronJob: running cron through virtual env
答案 2 :(得分:0)
只做一件事!! 您可以每天早上使用AWS并编写脚本来运行代码(您不会在AWS中遇到这些导入错误)。 每天您只需要打开AWS并下载PDF。