Over the past few years, with the rapid increase in the number of natural disasters, the need to provide smart emergency wireless communication services becomes crucial. Unmanned Aerial Vehicles (UAVs) got high attraction as promising candidates due to their unprecedented capabilities and broad flexibility. In this paper, we investigate the UAV-based emergency wireless communication network for a post-disaster area. Our optimization problem aims to optimize the UAV flight trajectory to maximize the number of visited ground users during the flight period. Then, a dual-cost-aware multi-armed bandit algorithm is adopted to tackle this problem under the limited available energy for both the UAV and ground users. Simulation results show that the proposed algorithm could solve the optimization problem and maximize the achievable throughput under these energy constraints.