-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_migration.py
More file actions
631 lines (496 loc) · 14.6 KB
/
Copy pathgithub_migration.py
File metadata and controls
631 lines (496 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
GitHub项目迁移脚本
将项目上传到GitHub,方便在新电脑上克隆使用
"""
import os
import subprocess
import json
from datetime import datetime
class GitHubMigration:
def __init__(self, project_root="."):
self.project_root = os.path.abspath(project_root)
self.timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
def check_git_installed(self):
"""检查Git是否安装"""
print("🔍 检查Git安装状态...")
try:
result = subprocess.run(["git", "--version"],
capture_output=True, text=True)
if result.returncode == 0:
print(f"✅ Git已安装: {result.stdout.strip()}")
return True
else:
print("❌ Git未安装")
return False
except FileNotFoundError:
print("❌ Git未安装或未添加到PATH")
print("💡 请先安装Git: https://git-scm.com/downloads")
return False
def init_git_repository(self):
"""初始化Git仓库"""
print("🔧 初始化Git仓库...")
try:
# 检查是否已经是Git仓库
if os.path.exists(os.path.join(self.project_root, ".git")):
print("✅ Git仓库已存在")
return True
# 初始化Git仓库
result = subprocess.run(["git", "init"],
cwd=self.project_root,
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Git仓库初始化成功")
return True
else:
print(f"❌ Git仓库初始化失败: {result.stderr}")
return False
except Exception as e:
print(f"❌ 初始化Git仓库时发生错误: {e}")
return False
def create_gitignore(self):
"""创建.gitignore文件"""
print("📝 创建.gitignore文件...")
gitignore_content = """# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Project specific
backup/
*.log
temp/
tmp/
# API keys and sensitive data
*_secret.json
*_private.json
.env.local
.env.production
# Large data files (optional - uncomment if needed)
# *.csv
# *.xlsx
# *.json
"""
gitignore_path = os.path.join(self.project_root, ".gitignore")
with open(gitignore_path, 'w', encoding='utf-8') as f:
f.write(gitignore_content)
print(f"✅ .gitignore文件已创建: {gitignore_path}")
def create_readme(self):
"""创建README.md文件"""
print("📖 创建README.md文件...")
readme_content = f"""# Cursor工作项目
## 项目概述
这是一个综合性的数据分析工具包,包含多个实用工具和项目:
- **Google Play评论分析系统** - 应用评论数据收集和分析
- **Twitter爬虫工具** - 社交媒体数据收集
- **SpotDL音乐下载器** - 音乐下载功能
- **Talkie项目分析** - 特定应用分析
- **通用分析工具** - 各种数据处理工具
## 功能特性
### 🔍 Google Play评论分析
- 自动爬取应用评论数据
- 智能分析用户需求和情感
- 生成可视化图表和报告
- 支持多种筛选条件
### 🐦 Twitter数据收集
- 用户推文爬取
- 数据格式化和导出
- 支持多种输出格式
### 🎵 音乐下载
- 基于SpotDL的音乐下载
- 支持多种音频格式
- 批量下载功能
### 📊 数据分析
- 评论情感分析
- 用户需求提取
- 数据可视化
- 报告生成
## 环境要求
- Python 3.8+
- 相关依赖包(见requirements.txt)
## 快速开始
### 1. 克隆项目
```bash
git clone <your-repo-url>
cd cursor
```
### 2. 安装依赖
```bash
pip install -r requirements.txt
```
### 3. 配置API密钥
编辑 `claude-config.json` 文件,填入你的API密钥:
```json
{{
"apiBaseUrl": "https://api.gptsapi.net",
"apiKey": "your-actual-api-key"
}}
```
### 4. 运行项目
```bash
# 使用启动器(推荐)
python project_launcher.py
# 或直接运行主程序
python main.py
```
## 项目结构
```
cursor/
├── main.py # 主程序入口
├── scraper.py # 爬虫工具
├── review_analyzer.py # 评论分析
├── review_visualizer.py # 数据可视化
├── project_launcher.py # 项目启动器
├── setup_environment.py # 环境配置脚本
├── backup_project.py # 项目备份脚本
├── requirements.txt # 依赖包列表
├── claude-config.json # API配置文件
├── Talkie项目/ # Talkie应用分析
├── SpotDL音乐下载/ # 音乐下载工具
├── Twitter爬虫/ # Twitter数据爬取
├── 通用工具/ # 通用分析工具
└── README.md # 项目说明
```
## 使用说明
### Google Play评论分析
```python
from main import GooglePlayAnalysisSystem
# 创建分析系统
system = GooglePlayAnalysisSystem()
# 运行完整分析
results = system.run_complete_analysis(
app_id="com.example.app",
max_reviews=1000,
app_name="Example App"
)
```
### Twitter数据爬取
```python
# 使用Twitter爬虫工具
python Twitter爬虫/twitter_scraper.py
```
### 音乐下载
```python
# 使用SpotDL下载音乐
python SpotDL音乐下载/spotdl_simple.py
```
## 输出文件
分析结果会保存在以下目录:
- `analysis_output/` - 分析结果
- `visualization_output/` - 可视化图表
- `talkie_analysis_output/` - Talkie分析结果
## 配置说明
### API配置
在 `claude-config.json` 中配置API密钥:
```json
{{
"apiBaseUrl": "https://api.gptsapi.net",
"apiKey": "your-api-key-here"
}}
```
### 依赖包
主要依赖包包括:
- google-play-scraper
- pandas
- numpy
- matplotlib
- seaborn
- requests
- jieba
## 故障排除
### 常见问题
1. **依赖包安装失败**
```bash
# 使用国内镜像源
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
```
2. **API密钥问题**
- 检查 `claude-config.json` 文件格式
- 确认API密钥有效性
- 检查网络连接
3. **Python版本问题**
- 确保使用Python 3.8或更高版本
- 检查PATH环境变量
## 贡献指南
1. Fork 项目
2. 创建功能分支
3. 提交更改
4. 推送到分支
5. 创建Pull Request
## 许可证
本项目采用MIT许可证。
## 联系方式
如有问题或建议,请通过以下方式联系:
- 创建Issue
- 发送邮件
---
**注意**: 请确保遵守相关平台的使用条款和API限制。
"""
readme_path = os.path.join(self.project_root, "README.md")
with open(readme_path, 'w', encoding='utf-8') as f:
f.write(readme_content)
print(f"✅ README.md文件已创建: {readme_path}")
def add_files_to_git(self):
"""添加文件到Git"""
print("📁 添加文件到Git...")
try:
# 添加所有文件
result = subprocess.run(["git", "add", "."],
cwd=self.project_root,
capture_output=True, text=True)
if result.returncode == 0:
print("✅ 文件添加成功")
return True
else:
print(f"❌ 文件添加失败: {result.stderr}")
return False
except Exception as e:
print(f"❌ 添加文件时发生错误: {e}")
return False
def commit_changes(self):
"""提交更改"""
print("💾 提交更改...")
commit_message = f"Initial commit - Project migration {self.timestamp}"
try:
result = subprocess.run(["git", "commit", "-m", commit_message],
cwd=self.project_root,
capture_output=True, text=True)
if result.returncode == 0:
print("✅ 更改提交成功")
return True
else:
print(f"❌ 更改提交失败: {result.stderr}")
return False
except Exception as e:
print(f"❌ 提交更改时发生错误: {e}")
return False
def create_github_repository_instructions(self):
"""创建GitHub仓库创建说明"""
print("📋 创建GitHub仓库说明...")
instructions = f"""
# GitHub仓库创建步骤
## 1. 在GitHub上创建新仓库
1. 访问 https://github.com
2. 点击右上角的 "+" 按钮
3. 选择 "New repository"
4. 填写仓库信息:
- Repository name: cursor-work-project
- Description: Cursor工作项目 - 数据分析工具包
- 选择 Public 或 Private
- 不要勾选 "Add a README file"(我们已经有了)
- 不要勾选 "Add .gitignore"(我们已经有了)
- 不要勾选 "Choose a license"(可选)
5. 点击 "Create repository"
## 2. 连接本地仓库到GitHub
在项目目录下运行以下命令:
```bash
# 添加远程仓库
git remote add origin https://github.com/YOUR_USERNAME/cursor-work-project.git
# 推送到GitHub
git branch -M main
git push -u origin main
```
## 3. 验证上传
1. 刷新GitHub页面
2. 确认所有文件都已上传
3. 检查README.md是否正确显示
## 4. 在新电脑上克隆项目
```bash
# 克隆项目
git clone https://github.com/YOUR_USERNAME/cursor-work-project.git
# 进入项目目录
cd cursor-work-project
# 安装依赖
pip install -r requirements.txt
# 配置API密钥
# 编辑 claude-config.json 文件
# 运行项目
python project_launcher.py
```
## 注意事项
1. 确保不要上传敏感信息(API密钥等)
2. 大文件(>100MB)需要使用Git LFS
3. 定期提交和推送更改
4. 使用有意义的提交信息
## 替代方案
如果不想使用命令行,也可以:
1. 在GitHub上创建空仓库
2. 使用GitHub Desktop客户端
3. 使用VS Code的Git集成功能
"""
instructions_file = os.path.join(self.project_root, "GitHub_Setup_Instructions.md")
with open(instructions_file, 'w', encoding='utf-8') as f:
f.write(instructions)
print(f"✅ GitHub设置说明已创建: {instructions_file}")
def show_git_status(self):
"""显示Git状态"""
print("📊 Git状态:")
print("=" * 40)
try:
# 显示状态
result = subprocess.run(["git", "status"],
cwd=self.project_root,
capture_output=True, text=True)
if result.returncode == 0:
print(result.stdout)
else:
print(f"❌ 获取Git状态失败: {result.stderr}")
except Exception as e:
print(f"❌ 获取Git状态时发生错误: {e}")
def run_migration(self):
"""运行完整迁移"""
print("🚀 开始GitHub项目迁移...")
print(f"📁 项目目录: {self.project_root}")
print("=" * 50)
success_steps = 0
total_steps = 6
# 1. 检查Git安装
if self.check_git_installed():
success_steps += 1
else:
print("❌ 请先安装Git")
return False
# 2. 初始化Git仓库
if self.init_git_repository():
success_steps += 1
# 3. 创建.gitignore
self.create_gitignore()
success_steps += 1
# 4. 创建README.md
self.create_readme()
success_steps += 1
# 5. 添加文件到Git
if self.add_files_to_git():
success_steps += 1
# 6. 提交更改
if self.commit_changes():
success_steps += 1
# 7. 创建GitHub设置说明
self.create_github_repository_instructions()
print("=" * 50)
print(f"📊 迁移准备完成: {success_steps}/{total_steps} 步骤成功")
if success_steps == total_steps:
print("🎉 项目已准备好上传到GitHub!")
print("\n💡 下一步操作:")
print("1. 查看 'GitHub_Setup_Instructions.md' 文件")
print("2. 在GitHub上创建新仓库")
print("3. 运行以下命令连接远程仓库:")
print(" git remote add origin <your-repo-url>")
print(" git push -u origin main")
print("4. 在新电脑上克隆项目")
else:
print("⚠️ 迁移准备部分成功,请检查失败的步骤")
# 显示Git状态
self.show_git_status()
return success_steps == total_steps
def main():
"""主函数"""
print("🌐 GitHub项目迁移工具")
print("=" * 50)
# 获取项目根目录
project_root = input("请输入项目根目录路径 (直接回车使用当前目录): ").strip()
if not project_root:
project_root = "."
# 创建迁移实例
migration = GitHubMigration(project_root)
# 运行迁移
success = migration.run_migration()
if success:
print("\n✅ GitHub迁移准备成功完成!")
print("📖 请查看 'GitHub_Setup_Instructions.md' 文件获取详细步骤")
else:
print("\n❌ GitHub迁移准备失败,请检查错误信息")
if __name__ == "__main__":
main()