Sunday, June 23, 2024

Read Emails using Gmail API

 

1. Follow the official guide to setup OAuth2

https://developers.google.com/gmail/api/guides

https://console.cloud.google.com/apis/credentials/consent 



2. Follow the official quick start to make sure you can print the label list

https://github.com/googleworkspace/java-samples/blob/main/gmail/quickstart/src/main/java/GmailQuickstart.java

3. Update the GmailQuickstart.java to print unread Emails:

setQ("is:unread") is used to retrieve the unread Emails only.

To mark the Emails as read, need add GMAIL_MODIFY: private static final List<String> SCOPES = Arrays.asList(GmailScopes.GMAIL_READONLY, GmailScopes.GMAIL_MODIFY);

Also need to remove the folder "tokens" under the project folder so that you can see a prompt to force a re-consent or reauthorization flow.

// private static final String USER = "me";

List<Message> mesageList = service.users().messages().list(USER).setQ("is:unread").execute().getMessages();

if(mesageList==null) {

System.out.println("No new messages!");

return;

}

for(Message message:mesageList) {

String subject = "";

String from = "";

String date = "";

Message fullMessage = service.users().messages().get(USER, message.getId()).execute();

List<MessagePartHeader> headers = fullMessage.getPayload().getHeaders();

for (MessagePartHeader header : headers) {

switch (header.getName()) {

case "Subject":

subject = header.getValue();

break;

case "From":

from = header.getValue();

break;

case "Date":

date = header.getValue();

break;

}

}

System.out.println("Subject: " + subject);

System.out.println("From: " + from);

System.out.println("Date: " + date);

markAsRead(service,USER,message.getId());

System.out.println();

}

}

private static void markAsRead(Gmail service, String userId, String messageId) throws IOException {

ModifyMessageRequest mods = new ModifyMessageRequest().setRemoveLabelIds(Collections.singletonList("UNREAD"));

service.users().messages().modify(userId, messageId, mods).execute();

}


The full runnable source code is on

https://github.com/auspix/java-samples/blob/main/gmail/quickstart/src/main/java/GmailReader.java






Friday, June 7, 2024

python web server to share the files

 python -m http.server 8000

python3 -m http.server 8000

so quest 3 can access

Thursday, June 6, 2024

Add JAVA_HOME for mac

 javac -version

/usr/libexec/java_home -V

vi ~/.zshrc
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH="$JAVA_HOME:$PATH"
exec zsh
echo $JAVA_HOME
to verify your change.

Monday, March 4, 2024

miniQMT自动交易

 https://blog.csdn.net/u010214511/article/details/130275793

http://dict.thinktrader.net/nativeApi/code_examples.html

1. Install Python 3.11.8

Need install Windows installer (64-bit) instead of Windows installer (ARM64) on Parallel Desktop (ARM) M2 chip

2. Install xtquant: pip install quant1x-xtquant

3. 

https://download.gjzq.com.cn/gjty/organ/gjzqqmt.rar

登录QMT极简模式,连接QMT客户端:

import random

from xtquant.xttrader import XtQuantTrader

path = r'C:\国金证券QMT交易端\userdata_mini'

session_id = int(random.randint(100000,999999))

xt_trader = XtQuantTrader(path, session_id)

xt_trader.start()

connect_result=xt_trader.connect()

print(connect_result)

if connect_result == 0:

print('Connected successfully!')

订阅账户:

acc = StockAccount('888XXXXXXX')

subscribe_result=xt_trader.subscribe(acc)

print(subscribe_result)

下单:

stock_code='000429.SZ'

order_id=xt_trader.order_stock(acc,stock_code,xtconstant.STOCK_BUY,100,xtconstant.FIX_PRICE,9.3)

xt_trader.cancel_order_stock(acc,1082384002)


    asset = xt_trader.query_stock_asset(acc)

    if asset:

        print("asset:")

        print("cash {0}".format(asset.cash))


run API auspix_detail takes 127 ms to PD

while it takes more thn 600 ms to Tencent Cloud

腾讯轻量云服务器以下规格足够用了:

腾讯云服务器可以随时销毁退钱,退钱的比例很好,几乎是全款

通用型
  • CPU - 2核 内存 - 4GB
  • 系统盘 - SSD云硬盘 90GB
  • 流量包 - 800GB/月(带宽:6Mbps)

C:\git\QMT>pip config get global.index-url
https://pypi.tuna.tsinghua.edu.cn/simple

To set a China-based mirror for faster downloads, you can change it as follows:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Friday, March 1, 2024

Breakpoint will not currently be hit. No symbols have been loaded for this document

 For C# Reflection/Dynamic loading module, got the message "Breakpoint will not currently be hit. No symbols have been loaded for this document" when trying to debug.

Already clean solution and rebuild, the below works for me

In VS, go to Tools --> Options --> Debugging --> General, and then cancel the checks in front of [Enable "Only My Code"] and [Require source files to exactly match the original version]. But this method you may have tried.


https://stackoverflow.com/questions/75142437/vs-2022-breakpoint-will-not-currently-be-hit-no-symbols-have-been-loaded-for-t  

Thursday, February 22, 2024

国外(加拿大)驾照换领国内(北京)驾照

 

需要提供:

1. 国外驾驶证原件及复印件

2. 身份证原件和复印件

3. 一寸白底彩色免冠照4张(注意考科目一的时候带上剩余照片)

4. 国外驾驶证翻译原件(不能自己翻译,可以用北京之外的翻译公司,我用的是淘宝找的成都博译翻译,不能用电子版)

5. 护照原件和复印件

6. 机动车驾驶人身体条件证明 (车管所旁边就有,一个体检机器,10分钟搞定)

这之后下载一个交管12123的手机App,预约考试,我约的是龙泉驾校。科目一题库应该就1600多道题,下载一个驾考宝典的App做一遍找出不会的,复习一下不会的就可以了。我准备比较仓促,模拟题做了好几遍只有考试当天早上以90分的成绩勉强通过一次,考试的时候也顺利一次通过(93)。考科目一当天要带着照片早点儿去,我约的是上午8:30到10:00,8点过一点儿主管就召集到教室开始讲考试注意事项了。手机有柜子存放,考试完毕签字后退柜子押金,就在驾校10分钟后就能领到驾照了,跟别的一样,6年有效期。



Sunday, January 21, 2024

local music files from MAC/PC to iPhone


需求: 准备回国,想把已经下载在计算机上的本地音乐文件包括APE,flac等无损格式到手机 iPhone

1. apple music: 可以添加play list,拖本地音乐文件加入,再同步。

两个问题,一是stuck on "Preparing To Sync",后来发现需要从activity monitor里面force quit MDCrashTool。另一个问题是一部分文件不能同步过去

2. QQ音乐

mac版qq音乐没有同步到设备的功能,windows版本有,但我的Parallel Desktop没有办法使用wireless connection,使用数据线连接QQ音乐能找到设备,但始终同步失败。上传到微盘很慢且一部分文件出错

3. 网易云音乐

都不能把本地文件加入到电脑端播放列表,直接删除

4. 酷我音乐

没有mac端桌面软件,但PC端桌面软件很好用,添加本地文件,传歌到设备都很完美。Parallel Desktop并未显示无线,但酷我能成功无线传歌到设备.

酷我的大问题是iphone广告太多了,点广告也只能有半个小时的播放时间。