Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# install dulu:
|
| 2 |
+
# pip install google-play-scraper pandas gradio
|
| 3 |
+
|
| 4 |
+
from google_play_scraper import reviews_all
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import tempfile
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
def scrape_reviews(app_id, language, country):
|
| 11 |
+
try:
|
| 12 |
+
# Ambil semua ulasan
|
| 13 |
+
reviews = reviews_all(
|
| 14 |
+
app_id,
|
| 15 |
+
sleep_milliseconds=0,
|
| 16 |
+
lang=language,
|
| 17 |
+
country=country
|
| 18 |
+
)
|
| 19 |
+
if not reviews:
|
| 20 |
+
return None, "Tidak ada ulasan ditemukan."
|
| 21 |
+
|
| 22 |
+
# Konversi ke DataFrame
|
| 23 |
+
df = pd.DataFrame(reviews)
|
| 24 |
+
df_filtered = df[['userName', 'score', 'at', 'content']]
|
| 25 |
+
df_filtered.columns = ['Nama Pengguna', 'Rating', 'Tanggal', 'Ulasan']
|
| 26 |
+
|
| 27 |
+
# Simpan sementara ke CSV
|
| 28 |
+
temp_dir = tempfile.mkdtemp()
|
| 29 |
+
file_path = os.path.join(temp_dir, f"ulasan_{app_id}.csv")
|
| 30 |
+
df_filtered.to_csv(file_path, index=False, encoding='utf-8-sig')
|
| 31 |
+
|
| 32 |
+
return file_path, f"Berhasil mengambil {len(df_filtered)} ulasan."
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return None, f"Error: {str(e)}"
|
| 35 |
+
|
| 36 |
+
# Buat UI Gradio
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# 📱 Scraper Ulasan Google Play Store")
|
| 39 |
+
gr.Markdown("Masukkan **App ID** Google Play, pilih bahasa dan negara, lalu unduh CSV ulasan.")
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
app_id_input = gr.Textbox(label="App ID", value="com.ruangguru.livestudents")
|
| 43 |
+
lang_input = gr.Textbox(label="Bahasa", value="id")
|
| 44 |
+
country_input = gr.Textbox(label="Negara", value="id")
|
| 45 |
+
|
| 46 |
+
scrape_button = gr.Button("Mulai Scraping")
|
| 47 |
+
output_file = gr.File(label="Download CSV", type="filepath")
|
| 48 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 49 |
+
|
| 50 |
+
scrape_button.click(
|
| 51 |
+
scrape_reviews,
|
| 52 |
+
inputs=[app_id_input, lang_input, country_input],
|
| 53 |
+
outputs=[output_file, status_output]
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
demo.launch()
|